sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
218 stars 44 forks source link

feat: ✨ numpy-array-use-type-var flag #188

Closed ringohoffman closed 7 months ago

ringohoffman commented 7 months ago

Fixes #187

Adds the flag --numpy-array-use-type-var which reformats the pybind11-generated numpy.ndarray[numpy.float32[m, 1]] annotation as numpy.ndarray[tuple[M, Literal[1]], numpy.dtype[numpy.float32]] using TypeVars; this allows for type-checker supported shape checking

Notable changes are:

ringohoffman commented 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?

?

Would we loop over these flags in tests/check-demo-stubs-generation.sh?

sizmailov commented 7 months ago

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.

ringohoffman commented 7 months ago

I gave it my best effort! Please let me know what you would have me change!

sizmailov commented 7 months ago

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.

sizmailov commented 7 months ago

Many thanks for contribution. I'll publish it as v2.4

ringohoffman commented 7 months ago

Does this affect the status of #113 or #115?

sizmailov commented 7 months ago

Indeed, #115 could be closed. I think #113 is not affected, since nptyping uses its own types.