Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix SI handling of special binary methods #860

Merged
merged 4 commits into from
Mar 4, 2024
Merged

fix SI handling of special binary methods #860

merged 4 commits into from
Mar 4, 2024

Conversation

gertjanvanzwieten
Copy link
Contributor

This PR fixes the way that SI handles special binary methods such as __add__ by returning NotImplemented rather than raising a TypeError. Additionally it introduces a special SI.DimensionError, and fixes two minor unrelated issues.

This patch replaces the _drop suffix to _op as it was originally intended.
This patch moves the type interence from util.cli to the _infer_type helper
function, and uses this in log_arguments. This fixes the situation in which
arguments without type annotation were not logged correctly due to failing
stringly serialization.
This patch introduces the SI.DimensionError class derived from TypeError, which
is raised instead of TypeError whenever an operation fails due to incompatible
units. In addition to allowing for more specific exception handling in general,
this will be used in particular in a subsequent commit to handle failing dunder
operations.
This patch fixes the behaviour or special binary methods (e.g. __add__) by
returning NotImplemented upon failure rather than raising DimensionError. See
https://docs.python.org/3.6/library/constants.html#NotImplemented.
@gertjanvanzwieten gertjanvanzwieten merged commit 43b9439 into master Mar 4, 2024
22 of 23 checks passed
@gertjanvanzwieten gertjanvanzwieten deleted the SI branch March 4, 2024 11:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants