python-attrs / python-attrs/attrs

Allow to pass a callable for field-level hash

Open
#1,076 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature
Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating the generated hash implementation and how eval globals are assembled; the issue does not name specific files or tests. Define how a callable for an individual field would be supplied and verify that generated hashes use it while preserving the other fields' hashing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.