-
Notifications
You must be signed in to change notification settings - Fork 52
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
feat: ✨ numpy-array-use-type-var flag #188
Conversation
reformat numpy.ndarray[numpy.float32[m, 1]] as numpy.ndarray[tuple[M, Literal[1]], numpy.dtype[numpy.float32]] using TypeVars; this allows for shape checking
Let me know what you want to do in the way of testing this. Does it make sense to create another set of sub-folders under each of
? Would we loop over these flags in |
17891fd
to
c1f8b07
Compare
it accepts a type argument, and if it is unknown it is typing.Any
c1f8b07
to
666b454
Compare
Unfortunately yes. Let's limit the tests for
No, let's add an extra command line option to |
since we will be testing both --numpy-array-wrap-with-annotated and --numpy-array-use-type-var (at least for 3.12 on pybind11 master), we put each in separate subfolders to make the tests easy to configure
…on.sh namely adding the option to be able to test --numpy-array-use-type-var
I gave it my best effort! Please let me know what you would have me change! |
Thanks! Looks good to me! The last minor thing. Let's make the CI job name for |
Many thanks for contribution. I'll publish it as |
Fixes #187
Adds the flag
--numpy-array-use-type-var
which reformats thepybind11
-generatednumpy.ndarray[numpy.float32[m, 1]]
annotation asnumpy.ndarray[tuple[M, Literal[1]], numpy.dtype[numpy.float32]]
usingTypeVar
s; this allows for type-checker supported shape checkingNotable changes are:
FixNumpyArrayDimTypeVar
, corresponding to the--numpy-array-use-type-var
flagTypeVar_
struct (appended_
to avoid conflicting withfrom typing import TypeVar
), and newModule.type_vars
fieldFixTypingTypeNames.parse_annotation_str()
was extracted into a helper method so that it could be additionally be called on every item ofresult.parameters
in order to expand theLiteral
inside theresult.parameters
into e.g.typing_extensions.Literal
FixScipyTypeArguments
was added to remove type arguments from anything fromscipy.sparse
, since they are not generic and do not accept any type arguments; the shape annotations provided by--numpy-array-wrap-with-annotated
are left intactFixNumpyDtype
forcesnumpy.dtype
withoutparameters
to benumpy.dtype[typing.Any]
since it expects one type argument