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

Accidentally using Language constructor breaks hash values #56

Open
doktoren opened this issue Mar 28, 2022 · 0 comments
Open

Accidentally using Language constructor breaks hash values #56

doktoren opened this issue Mar 28, 2022 · 0 comments

Comments

@doktoren
Copy link

I ran into the problem that

>>> Language("da") == Language.get("da")
True
>>> Language("da") in {Language.get("da")}
False

I know that the Language constructor specifies that It's inefficient to call this directly but it doesn't clearly say not to call it directly. And it's an easy mistake to do when it otherwise seems to work fine.

It seems that problem could easily be fixed by updating

    def __hash__(self) -> int:
        return hash(id(self))

to

    def __hash__(self) -> int:
        return hash(self._str_tag)

but I have no idea if other parts of the code doesn't work as expected either when calling the Language constructor directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant