Skip to content
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

Question: How to use/validate ndarray[...] types? #34

Closed
tgpfeiffer opened this issue Aug 26, 2020 · 3 comments
Closed

Question: How to use/validate ndarray[...] types? #34

tgpfeiffer opened this issue Aug 26, 2020 · 3 comments
Labels
question Further information is requested

Comments

@tgpfeiffer
Copy link
Contributor

At the moment, the code generated from pybind11-stubgen (0.6.0) has numpy types like

numpy.ndarray[numpy.float64, _Shape[4, 4]]
numpy.ndarray[numpy.int8]
numpy.ndarray[uint8]
numpy.ndarray[float64[3, 1], flags.writeable]

but how do I actually put them to use? I have the numpy-stubs (git+https://github.com/numpy/numpy-stubs.git@c49d2d6875971a669a166ea93ef998911af283a1) installed, but validating the above results in

error: "ndarray" expects no type arguments, but 2 given  [type-arg]

for the ndarray parameters and

error: Bad number of arguments for type alias, expected: 0, given: 2

on the same line (for _Shape I guess?).

At the moment I regex the additional type information away before feeding it to numpy, but how is this actually supposed to be used?

@sizmailov sizmailov added the question Further information is requested label Aug 26, 2020
@sizmailov
Copy link
Owner

Numpy generics are not supported by mypy and other tools as far as I know. Therefore type & shape information needs to be discarded to use mypy. There is a long-standing issue on mypy python/typing#513.

Note that numpy-stubs repo is obsolete and stubs are included in main numpy repo.

@tgpfeiffer
Copy link
Contributor Author

Therefore type & shape information needs to be discarded to use mypy

If that is the case, shouldn't pybind11-stubgen output all occurrences of numpy.ndarray without any type and shape information? Or is there some other application where that information can be put to use?

@sizmailov
Copy link
Owner

This is valuable information for users of the library who would navigate to stubs to see signatures (as augmentation to documentation).

I see it's tedious for automatic checks. I don't mind a command-line flag which would strip extra info from numpy arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants