You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Typing Error due to return type of astropy.units.core.def_unit #14632
It appears that forms like 10 << u.m gives error in type checking (pyright in my case):
The alternative form 10 << u.Unit("m") works fine.
I believe the issue is due to the computed return type of the def_unit function, which is a union of three: Unit, IrreducibleUnit, and (H0) -> Equivalency. The last item does not have the __rlshift__ operator defined.
Indeed, astropy has only minimal typing support so far. That said, I'm not sure why (H0) -> Equivalency is an output type. That seems wrong. Maybe @nstarman has more of a clue...
Yes, I frequently encounter this. In the absence of actual type hints pyright tries (and fails) to infer the types. Mypy has a different approach and labels this Any. Short of adding either type support or type stubs I don't think there's a good solution.
Activity
pllim commentedon Apr 14, 2023
I don't think we have full typing support yet but maybe @mhvk or @nstarman can clarify.
mhvk commentedon Apr 14, 2023
Indeed, astropy has only minimal typing support so far. That said, I'm not sure why
(H0) -> Equivalencyis an output type. That seems wrong. Maybe @nstarman has more of a clue...nstarman commentedon Apr 15, 2023
Yes, I frequently encounter this. In the absence of actual type hints pyright tries (and fails) to infer the types. Mypy has a different approach and labels this Any. Short of adding either type support or type stubs I don't think there's a good solution.
neutrinoceros commentedon Jan 25, 2024
Type hints are now actively being worked on. @nstarman do you know if this can be closed or linked to any of your existing PRs ?
nstarman commentedon Jan 25, 2024
Not yet. we haven't type hinted anything really in
units.