-
Notifications
You must be signed in to change notification settings - Fork 30
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
Why not support a "by convention" use of nptyping? #74
Comments
You could use from typing import Annotated
import numpy as np
Array2x3 = Annotated[np.ndarray, "2, [a, b, c]"]
def func(arr: Array2x3) -> None:
... Having |
You ask for much, misty mountain gorilla. I actually have a Sadly, I myself am currently the plugin and hooking mechanism. Ask – and ye shall probably eventually receive! However... Annotated[np.ndarray, "2, [a, b, c]"] ...that's pretty sketchy, bro. Ain't nobody dynamically evaluating, parsing, or otherwise munging ad-hoc strings embedded in type hints. On the other hand... from nptyping import NDArray, Shape
# Perhaps this...
Annotated[np.ndarray, Shape['2, 2']]
# ...or maybe this!
Annotated[np.ndarray, NDArray[Shape['2, 2']]] ...are both much more sensible. I don't know quite enough about |
Indeed, simply tacking on a string is unwise. |
For the people I work with, Pylance/Pyright support is important.
Would it be possible to use
nptyping
Shape annotations withAnnotated
, and document that possibility? note: that wouldn't require even importing thenptyping
.This could be done through the convention of having a string annotation in
Annotated
, or a dataclass wrapping a string.Then the downstream tools such as
beartype
andtypeguard
could be modified easily to support this syntax, and other type checkers/code analyzers would simply ignore the additional information.What do you think?
The text was updated successfully, but these errors were encountered: