| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Signed-off-by: Sachith Reddy <sachith.24bcs10403@sst.scaler.com>
There was a problem hiding this comment.
yeah, it may have been a mistake to add hash() to begin with, I think it only happened because ruff complained about not having it and it seemed easy to do...
In any case these fixes seem reasonable to me, thanks
Sorry, something went wrong.
|
Thanks for the review and the context on why hash() was added. |
Sorry, something went wrong.
Follow-up to theupdateframework#2973, which fixed Role.__hash__ and DelegatedRole.__hash__. The same bug remains in the other implementations: Signed, Root, MetaFile, Snapshot, Delegations, TargetFile, Targets and Metadata all pass a raw dict to hash(), so hash() raises "TypeError: unhashable type: 'dict'". Timestamp.__hash__ is itself correct but inherits the failure from Signed and MetaFile. All of these classes define __eq__, so __hash__ is required for them to be usable in a set or as a dict key. test_metadata_eq_.py covers __eq__ for exactly these classes but never calls hash(), which is why this went unnoticed. Hash a subset of immutable fields, as theupdateframework#2973 did. unrecognized_fields is excluded throughout since it holds arbitrary nested JSON. Snapshot.meta and Targets.targets contribute len() rather than their keys, to keep hashing O(1) for roles with many entries. Signed-off-by: Sachith Reddy <sachith.24bcs10403@sst.scaler.com>
| Back | FazBrowse Home | New Git URL |
Description
While going through _payload.py, I noticed that Role.__hash__() fails because it tries to hash keyids (a list) and unrecognized_fields (a dict) directly.
This PR:
The full test suite passes locally with tox.
I noticed similar patterns in a few other metadata classes, but kept this PR focused on Role and DelegatedRole.