Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutability issues #35

Open
Diaoul opened this issue Jul 14, 2021 · 0 comments · May be fixed by #50
Open

Immutability issues #35

Diaoul opened this issue Jul 14, 2021 · 0 comments · May be fixed by #50
Assignees
Labels
Milestone

Comments

@Diaoul
Copy link
Owner

Diaoul commented Jul 14, 2021

Currently babelfish implements the hash function to override default behavior and make it possible for objects to be keys in dictionaries and other useful features.
While this is a good thing, the way it is implemented makes it prone to some weird errors as explained in this lyft blog post:

>>> import babelfish
>>> fr = babelfish.Language("fra")
>>> fr_fr = babelfish.Language("fra", "FR")
>>> s = set([fr])
>>> fr in s
True
>>> fr_fr in s
False

All that is great, but if we modify the objects, things get weird because python expect the result of hash not to change:

>>> fr.country = babelfish.Country("FR")
>>> fr
<Language [fr-FR]>
>>> fr in s
False
>>> list(s)[0]
<Language [fr-FR]>
>>> fr_fr in s
False

I want to have true immutability of babelfish objects by making use of tuples (and derivatives) or at least faking it maybe with dataclasses frozen options.
This will surely be a breaking change.

@Diaoul Diaoul added the bug label Jul 14, 2021
@Diaoul Diaoul added this to the 1.0.0 milestone Jul 14, 2021
@Diaoul Diaoul self-assigned this Jul 14, 2021
@getzze getzze linked a pull request Sep 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant