Skip to content

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

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
dyollb opened this issue Apr 14, 2025 · 0 comments · Fixed by #5619
Closed
3 tasks done

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

dyollb opened this issue Apr 14, 2025 · 0 comments · Fixed by #5619
Labels
triage New bug, unverified

Comments

@dyollb
Copy link
Contributor

dyollb commented Apr 14, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant