pint
pint copied to clipboard
TypeError: unsupported operand type(s) for -: 'ParserHelper' and 'ParserHelper'
If you try and create a Quantity with a hyphen in the unit name, you get a very odd exception.
In [1]: import pint
In [2]: pint.Quantity(value=1, units="kilo-watt")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 pint.Quantity(value=1, units="kilo-watt")
File ~/path/to/.venv/lib/python3.12/site-packages/pint/pint_eval.py:383, in EvalTreeNode.evaluate(self, define_op, bin_op, un_op)
380 if op_text not in bin_op:
381 raise DefinitionSyntaxError(f"missing binary operator '{op_text}'")
--> 383 return bin_op[op_text](
384 self.left.evaluate(define_op, bin_op, un_op),
385 self.right.evaluate(define_op, bin_op, un_op),
386 )
387 elif self.operator:
388 assert isinstance(self.left, EvalTreeNode), "self.left not EvalTreeNode (4)"
TypeError: unsupported operand type(s) for -: 'ParserHelper' and 'ParserHelper'
I would expect this to raise the normal error:
UndefinedUnitError: 'megaflop' is not defined in the unit registry