Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unsupported operand type(s) for -: 'ParserHelper' and 'ParserHelper' #2029

Open
rob-levy-minimum opened this issue Jul 3, 2024 · 0 comments

Comments

@rob-levy-minimum
Copy link

rob-levy-minimum commented Jul 3, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant