Repository navigation
fix: make pebble.Notice hashable #2873
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
Closed
tonyandrewmeyer
wants to merge
1
commit into
canonical:main
from
tonyandrewmeyer:fix/notice-hashable
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is okay, but it seems to me that these values should form part of the hash. For example, we could include
tuple(sorted(notice.last_data.items()))in the hash (though not sure how to do that with dataclasses, off the top of my head.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with this is that the hash could change over the course of the object's lifetime, which breaks lookups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, the reason we're making it hashable is that we expect
last_datato be treated as immutable, even though frozen dataclass guarantees don't extend to mutable containers today ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we'd actually want a
KeyErrorif a user accidentally mutated the object? So we'd be intentionally implementing a__hash__that can break, so that it breaks loudly on user errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
last_datais not intended to be changed (I assume) but since we don't havefrozendictyet, it's a bit messy.I think it shouldn't be in the hash if you see a notice as being a Pebble notice, where
last_datais basically a shortcut to some extra information, but comparing two notices means comparing the key (but then the dates and occurrences probably shouldn't be in the hash either). It probably should be in the hash if you see a notice as being a snapshot of a Pebble notice at a specific time (more the Python object than the Pebble concept).I don't think this is a real issue. It came up when I did one of my semi-regular sweeps for issues by an agent, and it seemed worth bundling into a set of small fixes. But it does seem extremely unlikely that anyone does modify
last_datain practice. Maybe people want to be able to hash a notice (collecting them in a dict where the key is the dict key?) but no-one is doing that now, since it wouldn't work.Maybe we should just reject this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be in favour of just rejecting this. I agree it seems very unlikely for it to be an issue.