Closed ringohoffman closed 7 months ago
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 tests/stubs/python-*/pybind11-master
?
tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated
tests/stubs/python-3.7/pybind11-master/numpy-array-use-type-var
?
Would we loop over these flags in tests/check-demo-stubs-generation.sh
?
Does it make sense to create another set of sub-folders under each of
tests/stubs/python-*/pybind11-master
?* `tests/stubs/python-3.7/pybind11-master/numpy-array-wrap-with-annotated` * `tests/stubs/python-3.7/pybind11-master/numpy-array-use-type-var`
Unfortunately yes. Let's limit the tests for numpy-array-use-type-var
to the latest pybind11 and python.
Would we loop over these flags in
tests/check-demo-stubs-generation.sh
?
No, let's add an extra command line option to check-demo-stubs-generation.sh
for the numpy array transformation.
Let's create a separate entry for numpy-array-use-type-var
in gh-actions yml.
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 numpy-array-use-type-var
different from the default one.
Many thanks for contribution. I'll publish it as v2.4
Does this affect the status of #113 or #115?
Indeed, #115 could be closed.
I think #113 is not affected, since nptyping
uses its own types.
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