Open mmarchetti opened 6 years ago
I think it would be better to use some external function, e.g. change as_unum to
def as_unum(value, unit=None):
if unit is not None and not is_unit(unit):
raise NonBasicUnitError(unit)
if isinstance(value, Unum):
if unit is not None:
value = value.cast_unit(unit)
return value
return Unum(value) if unit is None else value * unit
>>> as_unum(torque, N*m)
0.102 [N·m]
Would you be willing to entertain a patch to make unit conversions easier?
I've experimented with two possibilities.
Overriding
__getitem__
to enable a bracket syntax for conversions:Overriding
__or__
instead:Examples: