Skip to content

[FLPY-61] Fixed operator overloading when using unyt types as lvalues #1092

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

Open
wants to merge 1 commit into
base: expressions
Choose a base branch
from

Conversation

andrzej-krupka
Copy link
Contributor

This was a weird one...

So basically the error comes down to the fact that unyt operators throw exceptions instead of returning the NotImplemented singleton when they fail. This prevents python from trying the __radd__ operator of the other operand (in our case, Expression.__radd__ which can handle unyt types just fine...). The dirty solution to this is overloading unyt's operators at runtime (see __soft_fail_*__ functions in user_code.py). Seems to work at first glance but I'm not sure how robust it is yet...

Tests work but it is a bit sketchy, might obfuscate some valid unyt errors if they arise in the context of expression parsing I think? Any ideas on how to improve this are welcome.

@benflexcompute benflexcompute changed the title Fixed operator overloading when using unyt types as lvalues [FLPY-61] Fixed operator overloading when using unyt types as lvalues May 27, 2025
@benflexcompute
Copy link
Collaborator

@andrzej-krupka Do we still need this PR?

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.

2 participants