Skip to content
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

default argument enum of -1 value fails to generate #152

Closed
battleguard opened this issue Sep 25, 2023 · 1 comment · Fixed by #153
Closed

default argument enum of -1 value fails to generate #152

battleguard opened this issue Sep 25, 2023 · 1 comment · Fixed by #153
Labels
bug Something isn't working

Comments

@battleguard
Copy link

battleguard commented Sep 25, 2023

Hello there is a small issue with the latest version and parsing default argument enums when the backing enum value is -1.

If you modify your test demo example here: https://github.com/sizmailov/pybind11-stubgen/blob/master/tests/demo-lib/include/demo/sublibA/ConsoleColors.h#L5

To the following:

enum class ConsoleForegroundColor {
    Green = 32,
    Yellow = 33,
    Blue = -1, // -1 instead of 34
    Magenta = 35
};

You should see an error similar to the following. (Note I tested this with a much simpler example thus the difference in pathing from the original)

$ pybind11-stubgen.exe pybind11_example --enum-class-locations="ConsoleForegroundColor:pybind11_example"
pybind11_stubgen - [  ERROR] In pybind11_example : Invalid expression '<ConsoleForegroundColor.Blue: -1>'
pybind11_stubgen - [WARNING] Raw C++ types/values were found in signatures extracted from docstrings.      
Please check the corresponding sections of pybind11 documentation to avoid common mistakes in binding code:
 - https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings
 - https://pybind11.readthedocs.io/en/latest/advanced/functions.html#default-arguments-revisited

This is occurring on the following binding in your test. https://github.com/sizmailov/pybind11-stubgen/blob/master/tests/py-demo/bindings/src/modules/enum.cpp

    m.def(
        "accept_defaulted_enum",
        [](const demo::sublibA::ConsoleForegroundColor &color) {},
        py::arg("color") = demo::sublibA::ConsoleForegroundColor::Blue);
@sizmailov sizmailov added the bug Something isn't working label Sep 25, 2023
sizmailov added a commit that referenced this issue Sep 26, 2023
@sizmailov
Copy link
Owner

Thanks!
Fixed in #153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants