Allow custom hashing function in `_make_hash`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by locating _make_hash and tracing how attrs generates hashes from class attributes. Review how a caller could provide a custom hashing function and determine the expected stable digest and collision behavior. Done means the supported API is documented and covered by tests for consistent results across interpreter sessions.
Written by the indexing model from the issue text.
Description
Hi again!
As we know, hash(x) in python yields different values across different interpreter sessions for security. It turns out that I am using attrs in all of my class definitions in a library and would like to bootstrap off of the programmatically generated hash function to essentially create a merkle tree. I would like to use hashlib.md5() or something similar and create a digest using all the attributes attrs can find in the class so that:
- the hash is consistent across runs.
- less importantly for me, but maybe more importantly for others, using a better hash allows for less collisions.
As always, please let me know if this is something attrs can/cannot support, and I will work with/around it accordingly. Thanks!
P.S. My workaround would be to define my own function to find all attributes using attr.asdict() and then creating a hash that way. Not terrible, but I figured it'd be worth asking for a "purer" solution.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/attrs
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100