You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also from a performance point of view, this might be bad, especially if we also want to support division by multiple types, and we have to call isinstance 3 times to get to the right type. And then isinstance(v, float) will reject ints, but the typing system will accept ints, so have to have an explicit runtime type check for ints also.
def__truediv__(self, other: Current|Voltage|float) ->Voltage|Current|Power:
ifisinstance(other, Current):
returnVoltage(self._base_value/other._base_value, exponent=0)
ifisinstance(other, Voltage):
returnCurrent(self._base_value/other._base_value, exponent=0)
ifisinstance(other, numbers.Real): # Only 1 extra `isinstance()` for all reals (`int` and `float` and whatever user-defined type that inherits from `numbers.Real`)returntype(self)(self._base_value/other, exponent=0)
raiseTypeError(
f"unsupported operand type(s) for /: '{type(self)}' and '{type(other)}'"
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
From:
@llucax
@shsms
@llucax
Beta Was this translation helpful? Give feedback.
All reactions