Closed MichaelTiemannOSC closed 5 months ago
Try adding units = None
to the class definition?
I imagine there will be more mypy issues... Would be good to get that working nicely
Thanks for that suggestion. Unfortunately mypy
doesn't support editable builds (https://github.com/python/mypy/issues/13392) and its doing a grand job preventing me from testing such a simple change. The line of code I'm trying to add is this:
units: Optional[_Unit] = None # Filled in by `construct_from_..._string`
But editing pint_array.py
in site-packages/pint_pandas
is not affecting the metadata that mypy is collecting. I'm not sufficiently experienced with mypy nor python build systems to know how to get mypy to use a particular path for satisfying its module dependencies.
As an amendment to the above, I did figure out that running mypy
directly, mypy preferred to look at pycache which somehow maintained an older version of the pint_array.py file I was modifying in place. However, when I ran mypy via pre-commit, the pre-comment script finds the wrong version of pint_array.py
because it insists on creating its own virtual environments from the named dependencies. I overrode that, changed language: python
to language: system
(following advice from https://jaredkhan.com/blog/mypy-pre-commit) and that was enough to confirm that the change was typed alright.
I'll leave this issue open as I doubt that's all the mypy issues that will come up... If we could get mypy running in the CI that would help
Here is some sample code that
mypy
cannot handle:mypy
throws the following error on the above:The particular problem is that the
PintType
that were are looking at here (pint[Gt CO2e]
) is forcibly given aunits
attribute in this part ofconstruct_from_string
:But
mypy
sees nounits
in the class declaration. Is there a way to preview tomypy
that aunits
property will come? Or do we just have to turn off typing when usingunits
from a PintType?