From a1482f66ecc360314b429dc4a4c2c5eab95bb518 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Tue, 26 Sep 2023 12:24:10 +0900 Subject: [PATCH 1/3] fix: Enum repr value regex --- pybind11_stubgen/parser/mixins/fix.py | 3 ++- tests/demo-lib/include/demo/sublibA/ConsoleColors.h | 3 ++- tests/py-demo/bindings/src/modules/enum.cpp | 3 ++- .../pybind11-master/demo/_bindings/enum.pyi | 11 +++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pybind11_stubgen/parser/mixins/fix.py b/pybind11_stubgen/parser/mixins/fix.py index 79afd61..65825ff 100644 --- a/pybind11_stubgen/parser/mixins/fix.py +++ b/pybind11_stubgen/parser/mixins/fix.py @@ -779,7 +779,8 @@ def parse_value_str(self, value: str) -> Value | InvalidExpression: class RewritePybind11EnumValueRepr(IParser): - _pybind11_enum_pattern = re.compile(r"<(?P\w+(\.\w+)+): (?P\d+)>") + _pybind11_enum_pattern = re.compile(r"<(?P\w+(\.\w+)+): (?P-?\d+)>") + # _pybind11_enum_pattern = re.compile(r"<(?P\w+(\.\w+)+): (?P\d+)>") _unknown_enum_classes: set[str] = set() def __init__(self): diff --git a/tests/demo-lib/include/demo/sublibA/ConsoleColors.h b/tests/demo-lib/include/demo/sublibA/ConsoleColors.h index 30d3663..5d97153 100644 --- a/tests/demo-lib/include/demo/sublibA/ConsoleColors.h +++ b/tests/demo-lib/include/demo/sublibA/ConsoleColors.h @@ -5,7 +5,8 @@ enum class ConsoleForegroundColor { Green = 32, Yellow = 33, Blue = 34, - Magenta = 35 + Magenta = 35, + None_ = -1 }; enum ConsoleBackgroundColor { diff --git a/tests/py-demo/bindings/src/modules/enum.cpp b/tests/py-demo/bindings/src/modules/enum.cpp index 014d290..67769f9 100644 --- a/tests/py-demo/bindings/src/modules/enum.cpp +++ b/tests/py-demo/bindings/src/modules/enum.cpp @@ -9,10 +9,11 @@ void bind_enum_module(py::module_&&m) { .value("Yellow", demo::sublibA::ConsoleForegroundColor::Yellow) .value("Blue", demo::sublibA::ConsoleForegroundColor::Blue) .value("Magenta", demo::sublibA::ConsoleForegroundColor::Magenta) + .value("None_", demo::sublibA::ConsoleForegroundColor::None_) .export_values(); m.def( "accept_defaulted_enum", [](const demo::sublibA::ConsoleForegroundColor &color) {}, - py::arg("color") = demo::sublibA::ConsoleForegroundColor::Blue); + py::arg("color") = demo::sublibA::ConsoleForegroundColor::None_); } diff --git a/tests/stubs/python-3.11/pybind11-master/demo/_bindings/enum.pyi b/tests/stubs/python-3.11/pybind11-master/demo/_bindings/enum.pyi index a1d2923..e3f9e10 100644 --- a/tests/stubs/python-3.11/pybind11-master/demo/_bindings/enum.pyi +++ b/tests/stubs/python-3.11/pybind11-master/demo/_bindings/enum.pyi @@ -7,6 +7,7 @@ __all__ = [ "ConsoleForegroundColor", "Green", "Magenta", + "None_", "Yellow", "accept_defaulted_enum", ] @@ -22,6 +23,8 @@ class ConsoleForegroundColor: Blue Magenta + + None_ """ Blue: typing.ClassVar[ @@ -33,12 +36,15 @@ class ConsoleForegroundColor: Magenta: typing.ClassVar[ ConsoleForegroundColor ] # value = + None_: typing.ClassVar[ + ConsoleForegroundColor + ] # value = Yellow: typing.ClassVar[ ConsoleForegroundColor ] # value = __members__: typing.ClassVar[ dict[str, ConsoleForegroundColor] - ] # value = {'Green': , 'Yellow': , 'Blue': , 'Magenta': } + ] # value = {'Green': , 'Yellow': , 'Blue': , 'Magenta': , 'None_': } def __eq__(self, other: typing.Any) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... @@ -55,10 +61,11 @@ class ConsoleForegroundColor: def value(self) -> int: ... def accept_defaulted_enum( - color: ConsoleForegroundColor = ConsoleForegroundColor.Blue, + color: ConsoleForegroundColor = ConsoleForegroundColor.None_, ) -> None: ... Blue: ConsoleForegroundColor # value = Green: ConsoleForegroundColor # value = Magenta: ConsoleForegroundColor # value = +None_: ConsoleForegroundColor # value = Yellow: ConsoleForegroundColor # value = From defe7e4cc6fd405c911b66a1eba51bdafc7d167f Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Tue, 26 Sep 2023 12:25:40 +0900 Subject: [PATCH 2/3] doc: Update CHANGELOG.md --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cdda2a..2bca6aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,16 @@ Changelog ========= +Version 2.2.1 (Sep 23, 2023) +-------------------------- +Changes: +- 🐛 fix: Missing `-?` in eum representation regex + Version 2.2.1 (Sep 23, 2023) -------------------------- Changes: -- 📝 Updater `--print-invalid-expressions-as-is` description +- 📝 Update `--print-invalid-expressions-as-is` description Version 2.2 (Sep 20, 2023) -------------------------- From ed047a0f2ea0197e7b1b3bc2a3d0343e58fd5536 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Tue, 26 Sep 2023 12:41:49 +0900 Subject: [PATCH 3/3] chore: Update stubs for Python 3.7-3.8 --- .../pybind11-master/demo/_bindings/enum.pyi | 11 +++++++++-- .../pybind11-master/demo/_bindings/enum.pyi | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/stubs/python-3.7/pybind11-master/demo/_bindings/enum.pyi b/tests/stubs/python-3.7/pybind11-master/demo/_bindings/enum.pyi index a1d2923..e3f9e10 100644 --- a/tests/stubs/python-3.7/pybind11-master/demo/_bindings/enum.pyi +++ b/tests/stubs/python-3.7/pybind11-master/demo/_bindings/enum.pyi @@ -7,6 +7,7 @@ __all__ = [ "ConsoleForegroundColor", "Green", "Magenta", + "None_", "Yellow", "accept_defaulted_enum", ] @@ -22,6 +23,8 @@ class ConsoleForegroundColor: Blue Magenta + + None_ """ Blue: typing.ClassVar[ @@ -33,12 +36,15 @@ class ConsoleForegroundColor: Magenta: typing.ClassVar[ ConsoleForegroundColor ] # value = + None_: typing.ClassVar[ + ConsoleForegroundColor + ] # value = Yellow: typing.ClassVar[ ConsoleForegroundColor ] # value = __members__: typing.ClassVar[ dict[str, ConsoleForegroundColor] - ] # value = {'Green': , 'Yellow': , 'Blue': , 'Magenta': } + ] # value = {'Green': , 'Yellow': , 'Blue': , 'Magenta': , 'None_': } def __eq__(self, other: typing.Any) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... @@ -55,10 +61,11 @@ class ConsoleForegroundColor: def value(self) -> int: ... def accept_defaulted_enum( - color: ConsoleForegroundColor = ConsoleForegroundColor.Blue, + color: ConsoleForegroundColor = ConsoleForegroundColor.None_, ) -> None: ... Blue: ConsoleForegroundColor # value = Green: ConsoleForegroundColor # value = Magenta: ConsoleForegroundColor # value = +None_: ConsoleForegroundColor # value = Yellow: ConsoleForegroundColor # value = diff --git a/tests/stubs/python-3.8/pybind11-master/demo/_bindings/enum.pyi b/tests/stubs/python-3.8/pybind11-master/demo/_bindings/enum.pyi index a1d2923..e3f9e10 100644 --- a/tests/stubs/python-3.8/pybind11-master/demo/_bindings/enum.pyi +++ b/tests/stubs/python-3.8/pybind11-master/demo/_bindings/enum.pyi @@ -7,6 +7,7 @@ __all__ = [ "ConsoleForegroundColor", "Green", "Magenta", + "None_", "Yellow", "accept_defaulted_enum", ] @@ -22,6 +23,8 @@ class ConsoleForegroundColor: Blue Magenta + + None_ """ Blue: typing.ClassVar[ @@ -33,12 +36,15 @@ class ConsoleForegroundColor: Magenta: typing.ClassVar[ ConsoleForegroundColor ] # value = + None_: typing.ClassVar[ + ConsoleForegroundColor + ] # value = Yellow: typing.ClassVar[ ConsoleForegroundColor ] # value = __members__: typing.ClassVar[ dict[str, ConsoleForegroundColor] - ] # value = {'Green': , 'Yellow': , 'Blue': , 'Magenta': } + ] # value = {'Green': , 'Yellow': , 'Blue': , 'Magenta': , 'None_': } def __eq__(self, other: typing.Any) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... @@ -55,10 +61,11 @@ class ConsoleForegroundColor: def value(self) -> int: ... def accept_defaulted_enum( - color: ConsoleForegroundColor = ConsoleForegroundColor.Blue, + color: ConsoleForegroundColor = ConsoleForegroundColor.None_, ) -> None: ... Blue: ConsoleForegroundColor # value = Green: ConsoleForegroundColor # value = Magenta: ConsoleForegroundColor # value = +None_: ConsoleForegroundColor # value = Yellow: ConsoleForegroundColor # value =