hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.37k stars 466 forks source link

Typing of Quantity.to() raises mypy error #1827

Open hassec opened 1 year ago

hassec commented 1 year ago

When type checking the below snippet with mypy (v.1.4.1), it raises an error. Pint version is 0.22.

import pint

def foo(a: pint.Quantity, b: pint.Unit) -> pint.Quantity:
    return a.to(b)

Error:

type.py:4: error: Incompatible return value type (got "PlainQuantity[Any]", expected "Quantity")  [return-value]
vallsv commented 2 months ago

Got the same with isinstance(foo, pint.Quantity).

Is anybody know if there is actually a "right" way to use pint and mypy?