How to determine which instance of an operator is being called?
I have a class called MyData that has __mul__ and __rmul__ defined (along
with all the other arithmetic operators). Whenever these methods are used,
it should always return a value of type MyData. However, I discovered that
a * myDataObj is not the same as myDataObj * a, depending on the type of
a. Specifically, if a was an int, it worked fine, but if a was a float
then the first configuration return an array (my object has a numpy array
as a member, and MyData.__getitem__ returns slices of that array) and the
second configuration returns the proper value of type MyData.
Is there any way to determine the calling order of the operator in an
expression like this?
No comments:
Post a Comment