Skip to content

Improve type handling in rich comparisons - #111

Merged
Ezibenroc merged 1 commit into
Ezibenroc:masterfrom
PeterJCLaw:improve-rich-comparisons
Jan 30, 2024
Merged

Improve type handling in rich comparisons#111
Ezibenroc merged 1 commit into
Ezibenroc:masterfrom
PeterJCLaw:improve-rich-comparisons

Conversation

@PeterJCLaw

Copy link
Copy Markdown
Contributor

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).

Fixes #107 plus an issue with None found while writing the tests.

Comment thread test.py
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, should this be alongside test_wrong_add rather than here?

@PeterJCLaw

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Owner

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.

Do you want to first merge #110 or #111 ?

@PeterJCLaw

Copy link
Copy Markdown
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
PeterJCLaw force-pushed the improve-rich-comparisons branch from 784a24c to 9636a85 Compare January 28, 2024 22:17
@Ezibenroc
Ezibenroc merged commit 4890bdb into Ezibenroc:master Jan 30, 2024
@Ezibenroc

Copy link
Copy Markdown
Owner

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError raised for equality comparison with other object

2 participants