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.
Fixes #596.
The two decorators
_left_operator
and_right_operator
handle getting the.value
and checks for left-side and right-side operator, respectively.For the arithmetic itself, the base Python types are used, and then converted back into AiiDA types using
to_aiida_type
. This function usessingledispatch
to select the right function corresponding to the type of the value.I removed the inline operations (
__iadd__
etc.) because that doesn't really go well if the type of the return value could be changed. It would be possible to implement, but IMO doesn't give much benefit. The current version is consistent with the behavior of the corresponding Python types, which are immutable. The operations (+=
etc.) can still be used, since Python just falls back on__add__
.Another detail is that the comparisons now return
Bool
, notbool
. This should be fine since theBool
now converts tobool
correctly, but it could be changed back if needed.Side note: I think that
to_aiida_type
should also be used to automatically infer at least the basic types when passing arguments to processes. Having to explicitly callStr
,Int
etc. on all inputs is just unnecessary clutter.