-
Notifications
You must be signed in to change notification settings - Fork 146
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
PMap.__getitem__ gets the wrong value #212
Comments
Sorry, I didn't introduce myself. My name is Bruno and I work with python development for visual effects pipelines. |
Thinking more about it, I guess my example breaks the rules of how hashing and equality should work in good python code in the first place. So even though pmap seems to behave differently than a regular dict in this case, maybe it doesn't matter since this particular example is bad and should not be implemented that way anyway. |
Hi Bruno! OK, no worries. Having two object that compare equal but result in different hashes seems odd to me. I'm a bit surprised about the difference between Python 2 and 3 though. I need to do some investigation. Hope to find some time in the next days. |
This difference comes from an implementation detail in the python dict c-code. Infact, the code in the example for the ordinary dict only passes because the keys are enumerated in the order they were added to the dict. If you include the lines As this behaviour is not in the spec for dict, it may change in the future. |
just a suggestion, but eq returning True with hashcode returning nonequal values could throw an exception at runtime? to me that would feel the right thing. |
PMap.__getitem__
will return the wrong value if the object used for the key defines a unique__hash__
and a custom__eq__
method.Repro (tested with python 3.8 and pyrsistent 0.17.3):
The text was updated successfully, but these errors were encountered: