Improve type handling in rich comparisons - #111
Merged
Conversation
PeterJCLaw
commented
Jan 27, 2024
Comment on lines
+403
to
+553
| @given(bitmap_cls, hyp_collection, st.booleans()) | ||
| def test_comparison_other_objects(self, cls, values, cow): | ||
| for op in [operator.le, operator.ge, operator.lt, operator.gt]: | ||
| bm = cls(values, copy_on_write=cow) | ||
| with self.assertRaises(TypeError): | ||
| op(bm, 42) | ||
| with self.assertRaises(TypeError): | ||
| op(bm, None) | ||
|
|
Contributor
Author
There was a problem hiding this comment.
Hrm, should this be alongside test_wrong_add rather than here?
Contributor
Author
|
Note: I suspect that this will conflict with #110; probably best to get that one in first as this PR will be the easier to re-work once that's in place. |
Ezibenroc
approved these changes
Jan 28, 2024
Owner
Contributor
Author
|
If we can merge #110 first I'm expecting that to be the easier way around. |
Previously an error was raised when doing equality comparisons between BitMaps and other instance types, which is unexpected in Python. Move over to implementing each of the rich comparison methods directly so that we can more match the usual pattern of allowed (and rejected) comparisons. Also explicitly check for `None` when validating that two BitMaps can be compared, so that the error message emitted in that case is of the more expected type (i.e: `TypeError` rather than `AttributeError`).
PeterJCLaw
force-pushed
the
improve-rich-comparisons
branch
from
January 28, 2024 22:17
784a24c to
9636a85
Compare
Owner
|
Thank you ! |
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.
Previously an error was raised when doing equality comparisons between BitMaps and other instance types, which is unexpected in Python. Move over to implementing each of the rich comparison methods directly so that we can more match the usual pattern of allowed (and rejected) comparisons.
Also explicitly check for
Nonewhen validating that two BitMaps can be compared, so that the error message emitted in that case is of the more expected type (i.e:TypeErrorrather thanAttributeError).Fixes #107 plus an issue with
Nonefound while writing the tests.