Skip to content

[BUG]: Invalid typing for std::array? #3912

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

Closed
3 tasks done
Holt59 opened this issue Apr 28, 2022 · 3 comments · Fixed by #4679
Closed
3 tasks done

[BUG]: Invalid typing for std::array? #3912

Holt59 opened this issue Apr 28, 2022 · 3 comments · Fixed by #4679
Labels
bug signatures Issue about static signatures

Comments

@Holt59
Copy link

Holt59 commented Apr 28, 2022

Required prerequisites

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"};
    });
}
@Holt59 Holt59 added the triage New bug, unverified label Apr 28, 2022
@bricerebsamen
Copy link

@sizmailov for your attention please

@Skylion007
Copy link
Collaborator

Oddly enough, this is expected and tested behavior:

assert doc(m.cast_array) == "cast_array() -> List[int[2]]"
. @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?

@Skylion007 Skylion007 added bug and removed triage New bug, unverified labels Apr 29, 2022
Skylion007 added a commit to Skylion007/pybind11 that referenced this issue Apr 29, 2022
@Skylion007
Copy link
Collaborator

@henryiii Any idea how we can support typing extensions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug signatures Issue about static signatures
Projects
None yet
3 participants