attrs icon indicating copy to clipboard operation
attrs copied to clipboard

Allow to pass a callable for field-level hash

Open hynek opened this issue 2 years ago • 1 comments

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 avatar Jan 02 '23 15:01 hynek

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

Tinche avatar Jan 02 '23 15:01 Tinche