Skip to content

Fix compatibility of Tuple's hash function #3460

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TeamTamoad
Copy link
Contributor

Change hash function implementation of Tuple to compatible with CPython's implementation.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks great, but by looking at the CI result, range() hash must follow the reuslt of tuple. Could you also update range.__hash__ in the same way?

You can extract hash function like fn tuple_hash(elements: &[PyObjectRef], vm: &VirtualMachine) and call it form PyTuple::hash like tuple_hash(zelf.as_slice())

@youknowone
Copy link
Member

The new bug is bug of exec. Somehow when __hash__ is added by exec, it doesn't run update_slot.
As the result, the upper test passes but the lower test fails

import dataclasses

@dataclasses.dataclass(unsafe_hash=True)
class X:
    pass


a = X().__hash__()
b = ().__hash__()
assert a == b, '{} {}'.format(a, b)

a = hash(X())
b = hash(())
assert a == b, '{} {}'.format(a, b)

@youknowone
Copy link
Member

@coolreader18 do you have any idea?

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

Successfully merging this pull request may close these issues.

2 participants