[FLPY-61] Fixed operator overloading when using unyt types as lvalues #1092
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.
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 inuser_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.