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

Allow to pass a callable for field-level hash #1076

Open
hynek opened this issue Jan 2, 2023 · 1 comment
Open

Allow to pass a callable for field-level hash #1076

hynek opened this issue Jan 2, 2023 · 1 comment
Labels

Comments

@hynek
Copy link
Member

hynek commented Jan 2, 2023

Apparently, being able to customize the hashing of individual fields is something interesting for NumPy users: https://stackoverflow.com/q/74975393/476759


I guess the idea would be to create a __hash__ that looks like this:

def __hash__(self):
    return hash((self.a, custom_hash_for_b(self.b)))

while injecting custom_hash_for_b into eval's globals.

@hynek hynek changed the title Allow to pass a callable for hash Allow to pass a callable for field-level hash Jan 2, 2023
@hynek hynek added the Feature label Jan 2, 2023
@Tinche
Copy link
Member

Tinche commented Jan 2, 2023

Don't be a coward and inject it into __hash__ as a parameter default.

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

No branches or pull requests

2 participants