sizmailov / pybind11-stubgen

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

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

Closed battleguard closed 11 months ago

battleguard commented 11 months ago

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 commented 11 months ago

Thanks! Fixed in #153