Skip to content

[BUG]: non-pythonic function signature for native_enum #5618

Closed
@dyollb

Description

@dyollb

Required prerequisites

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

master

Problem description

I tested using pybind11-stubgen with the latest pybind11 master. When the native_enum is used in function signatures, pybind11-stubgen cannot "link" the argument to the enum from the module (see this issue). To test if something is "wrong" in pybind11 I wrote following test:

#include <pybind11/native_enum.h>

namespace test {
    enum class fake{ x };
    enum class native{ x };
}

TEST_SUBMODULE(docstring_options, m) {
    // test_docstring_options
    {
        py::enum_<test::fake>(m, "Fake").value("x", test::fake::x);
        py::native_enum<test::native>(m, "Native", "enum.Enum").value("x", test::native::x).finalize();

        options.enable_function_signatures();

        m.def("test_function_enum", [](test::fake, test::native){}, py::arg("f"), py::arg("n"));
    }
}

and

    assert m.test_function_enum.__doc__.starts-with(
        "test_function_enum(f: pybind11_tests.docstring_options.Fake, n: pybind11_tests.docstring_options.Native) -> None"
    )

This fails because the signature of the second argument is "C++-like", i.e. test::native instead of pybind11_tests.docstring_options.Native.

E       AssertionError: assert False
E        +  where False = <built-in method startswith of str object at 0x1179b92c0>('test_function_enum(f: pybind11_tests.docstring_options.Fake, n: pybind11_tests.docstring_options.Native) -> None')
E        +    where <built-in method startswith of str object at 0x1179b92c0> = 'test_function_enum(f: pybind11_tests.docstring_options.Fake, n: test::native) -> None\n'.startswith
E        +      where 'test_function_enum(f: pybind11_tests.docstring_options.Fake, n: test::native) -> None\n' = <built-in method test_function_enum of pybind11_detail_function_record_v1_system_libcpp_abi1 object at 0x105b20990>.__doc__
E        +        where <built-in method test_function_enum of pybind11_detail_function_record_v1_system_libcpp_abi1 object at 0x105b20990> = m.test_function_enum


../../tests/test_docstring_options.py:31: AssertionError

Reproducible example code


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

Not a regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions