sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
228 stars 45 forks source link

typing.Annotated in a version of python that doesn't support it #167

Closed virtuald closed 10 months ago

virtuald commented 10 months ago

So if I have..

// the array parameter is returned
int fnParamArrayOut(int x[3])
{
    x[0] = 5;
    x[1] = 6;
    x[2] = 7;
    return 4;
}

and I wrap it like this:

    m.def(
        "fnParamArrayOut",
        []() {
          std::array<int, 3> x{};
          auto __ret = ::fnParamArrayOut(std::move(x).data());
          return std::make_tuple(__ret, x);
        });

Then I get this stub:

def fnParamArrayOut() -> tuple[int, typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(3)]]:
    pass

Which is fine, but in https://github.com/robotpy/robotpy-build/actions/runs/6600503330/job/17930593375#step:10:921 this fails on Python 3.8 because it can't find typing.Annotated.

I tried to just install typing-extensions, but that doesn't seem to help. Any thoughts on the best way to deal with this? My feeling is that I don't really care about this error at all on an older python, so maybe there's a way to special-case typing?

sizmailov commented 10 months ago

Hi!

Thanks for the report. I didn't much pay attention to older versions and didn't realize it could cause troubles in CI.

Fixed in 2.3.3

virtuald commented 10 months ago

Thanks for fixing that, looks good here!