Skip to content

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

Closed

Description

@Holt59

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"};
    });
}

Activity

  1. bricerebsamen commented on Apr 28, 2022

    @bricerebsamen

    @sizmailov for your attention please

  2. Skylion007 commented on Apr 29, 2022

    @Skylion007
    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?

  3. added and removed
    triageNew bug, unverified
    on Apr 29, 2022
  4. added a commit that references this issue on Apr 29, 2022
    909b870
  5. Skylion007 commented on May 3, 2022

    @Skylion007
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsignaturesIssue about static signatures

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions