-
Notifications
You must be signed in to change notification settings - Fork 465
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
Type hints? #778
Comments
It is an interesting proposal. But this would require to create another class for type hinting analog to how |
I would love type hinting support in pint, but this is indeed tricky. I've been thinking about this for the last hour or so and it just keeps getting harder. The fact that there are lots of different units that are equivalent dimensionality but this isn't known until runtime is the killer for me. The function
works equally well if given:
so My instinct is that the only way to do this would be to maintain a separate set of pyi files that approximates pint without much of the depth, hard coding the dimensionality of certain units that are in common usage, but that would cause problems for anyone using a registry backed by definitions files that have any units that differ in dimensionality or contain any units not in the core set. Even then, I'm not sure e'd be able to handle building dimensionality on the fly, maybe for the simple units like I'd be curious to know if people think how important it is for various things to happen automatically, but given the difficulties I can't imagine that this would support official typing anytime soon. |
I'm using type hinting and would love to have it. Even a generic |
One possibility here might be a mypy plugin: https://mypy.readthedocs.io/en/stable/extending_mypy.html#configuring-mypy-to-use-plugins . Hypothetically, a plugin might be able to work with A = TypeVar("A")
B = TypeVar("B")
def mul_any(a: Quantity[A], b: Quantity[B]) -> Quantity[A * B]:
return a * b For instance, other mypy plugins:
(edit: ah, I see #1166 discusses a syntax too.) |
Hello, My objective would be to write something like:
as was suggested by @likewei92 and I read with interest the other posts too. For reference, a page about my work is at ruralwater and please feel free to contact me. |
This is something on the roadmap @claudiofinizio it would be great if you can contribute. I am closing this to move the discussion to #1166 |
Is it possible to expose certain classes like Quantity such that they can be used with type hints (https://docs.python.org/3/library/typing.html)?
For example like this:
The text was updated successfully, but these errors were encountered: