fix(jwk): handle KeySet equality with unrelated types - #106
Open
janmrow wants to merge 1 commit into
Open
Conversation
lepture
reviewed
Sep 8, 2026
| def __eq__(self, other: t.Any) -> bool: | ||
| assert isinstance(other, KeySet) | ||
| if not isinstance(other, KeySet): | ||
| return NotImplemented |
Contributor
Author
There was a problem hiding this comment.
I considered False, but switched to NotImplemented, because that follows Python's equality protocol and allows the other operand's __eq__ to handle the comparison if appropriate.
But for KeySet that extra behavior probably isn't needed.
Looks likeFalse is simpler here and matches BaseKey.__eq__, so I suppose that fits better to the project. Happy to change it.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
KeySet.__eq__currently raises an exception when aKeySetis compared with an unrelated type.This PR returns
NotImplementedfor unsupported types. This lets Python handle the comparison, while keeping existingKeySet-to-KeySetcomparisons unchanged.Regression tests cover comparisons with unrelated types, also including reflected equality.
Tests on local:
pytest tests/ -qmypy src/joserfc/_keys.py