pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[BUG]: array_t stub is incorrect.

Open gentlegiantJGC opened this issue 1 year ago • 1 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [X] Consider asking first in the Gitter chat room or in a Discussion.

What version (or hash if on master) of pybind11 are you using?

2.13.5

Problem description

The stub files generated by handle_type_name are incorrect for array_t.

The correct type hint for py::array_t<std::uint32_t> should be one of:

  1. numpy.ndarray[typing.Any, numpy.uint32] First argument is shape, second argument is type.
  2. numpy.typing.NDArray[numpy.uint32] Only argument is type.

but pybind creates numpy.ndarray[numpy.uint32] which raises the following mypy error.

error: "ndarray" expects 2 type arguments, but 1 given

Doc: https://numpy.org/doc/1.21/reference/typing.html#numpy.typing.NDArray

Is there some reason why this is wrong? I can submit a pull request if you tell me which form you prefer.

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

Not a regression

gentlegiantJGC avatar Sep 03 '24 12:09 gentlegiantJGC

#5212

gentlegiantJGC avatar Sep 03 '24 15:09 gentlegiantJGC

This was fixed in #5212

gentlegiantJGC avatar Apr 23 '25 14:04 gentlegiantJGC