pybind11
pybind11 copied to clipboard
[BUG]: Invalid typing for `std::array`?
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.
Problem description
When returning a std::array, the typing information is invalid, e.g. List[str[2]] for the code below. This causes tool such as mypy's stubgen or pybind11-stubgen to produce invalid stubs.
I guess it would be valid to generate List[str] in this case since Python does not have information about the size anyway?
Reproducible example code
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
PYBIND11_MODULE(cpp_module, m)
{
m.def("arr", []() -> std::array<const char*, 2> {
return {"foo", "bar"};
});
}
@sizmailov for your attention please
Oddly enough, this is expected and tested behavior: https://github.com/pybind/pybind11/blob/75007dda72ad4508064c1f080394eae50d3a61ee/tests/test_stl.py#L42 . @rwgk @henryiii This doesn't seem to be a valid typing extension. Any idea why this data is included? We can use Annotated, but we need typing_extensions to backport that behavior. I guess we should remove that data or change the return type of a caster to a tuple / something that can handle it?
@henryiii Any idea how we can support typing extensions?