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

Fix enum value regexp #153

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
--------------------------
Expand Down
3 changes: 2 additions & 1 deletion pybind11_stubgen/parser/mixins/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ def parse_value_str(self, value: str) -> Value | InvalidExpression:


class RewritePybind11EnumValueRepr(IParser):
_pybind11_enum_pattern = re.compile(r"<(?P<enum>\w+(\.\w+)+): (?P<value>\d+)>")
_pybind11_enum_pattern = re.compile(r"<(?P<enum>\w+(\.\w+)+): (?P<value>-?\d+)>")
# _pybind11_enum_pattern = re.compile(r"<(?P<enum>\w+(\.\w+)+): (?P<value>\d+)>")
_unknown_enum_classes: set[str] = set()

def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/demo-lib/include/demo/sublibA/ConsoleColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ enum class ConsoleForegroundColor {
Green = 32,
Yellow = 33,
Blue = 34,
Magenta = 35
Magenta = 35,
None_ = -1
};

enum ConsoleBackgroundColor {
Expand Down
3 changes: 2 additions & 1 deletion tests/py-demo/bindings/src/modules/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
11 changes: 9 additions & 2 deletions tests/stubs/python-3.11/pybind11-master/demo/_bindings/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __all__ = [
"ConsoleForegroundColor",
"Green",
"Magenta",
"None_",
"Yellow",
"accept_defaulted_enum",
]
Expand All @@ -22,6 +23,8 @@ class ConsoleForegroundColor:
Blue

Magenta

None_
"""

Blue: typing.ClassVar[
Expand All @@ -33,12 +36,15 @@ class ConsoleForegroundColor:
Magenta: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.Magenta: 35>
None_: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.None_: -1>
Yellow: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.Yellow: 33>
__members__: typing.ClassVar[
dict[str, ConsoleForegroundColor]
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>, 'None_': <ConsoleForegroundColor.None_: -1>}
def __eq__(self, other: typing.Any) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
Expand All @@ -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 = <ConsoleForegroundColor.Blue: 34>
Green: ConsoleForegroundColor # value = <ConsoleForegroundColor.Green: 32>
Magenta: ConsoleForegroundColor # value = <ConsoleForegroundColor.Magenta: 35>
None_: ConsoleForegroundColor # value = <ConsoleForegroundColor.None_: -1>
Yellow: ConsoleForegroundColor # value = <ConsoleForegroundColor.Yellow: 33>
11 changes: 9 additions & 2 deletions tests/stubs/python-3.7/pybind11-master/demo/_bindings/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __all__ = [
"ConsoleForegroundColor",
"Green",
"Magenta",
"None_",
"Yellow",
"accept_defaulted_enum",
]
Expand All @@ -22,6 +23,8 @@ class ConsoleForegroundColor:
Blue

Magenta

None_
"""

Blue: typing.ClassVar[
Expand All @@ -33,12 +36,15 @@ class ConsoleForegroundColor:
Magenta: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.Magenta: 35>
None_: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.None_: -1>
Yellow: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.Yellow: 33>
__members__: typing.ClassVar[
dict[str, ConsoleForegroundColor]
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>, 'None_': <ConsoleForegroundColor.None_: -1>}
def __eq__(self, other: typing.Any) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
Expand All @@ -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 = <ConsoleForegroundColor.Blue: 34>
Green: ConsoleForegroundColor # value = <ConsoleForegroundColor.Green: 32>
Magenta: ConsoleForegroundColor # value = <ConsoleForegroundColor.Magenta: 35>
None_: ConsoleForegroundColor # value = <ConsoleForegroundColor.None_: -1>
Yellow: ConsoleForegroundColor # value = <ConsoleForegroundColor.Yellow: 33>
11 changes: 9 additions & 2 deletions tests/stubs/python-3.8/pybind11-master/demo/_bindings/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __all__ = [
"ConsoleForegroundColor",
"Green",
"Magenta",
"None_",
"Yellow",
"accept_defaulted_enum",
]
Expand All @@ -22,6 +23,8 @@ class ConsoleForegroundColor:
Blue

Magenta

None_
"""

Blue: typing.ClassVar[
Expand All @@ -33,12 +36,15 @@ class ConsoleForegroundColor:
Magenta: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.Magenta: 35>
None_: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.None_: -1>
Yellow: typing.ClassVar[
ConsoleForegroundColor
] # value = <ConsoleForegroundColor.Yellow: 33>
__members__: typing.ClassVar[
dict[str, ConsoleForegroundColor]
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>, 'None_': <ConsoleForegroundColor.None_: -1>}
def __eq__(self, other: typing.Any) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
Expand All @@ -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 = <ConsoleForegroundColor.Blue: 34>
Green: ConsoleForegroundColor # value = <ConsoleForegroundColor.Green: 32>
Magenta: ConsoleForegroundColor # value = <ConsoleForegroundColor.Magenta: 35>
None_: ConsoleForegroundColor # value = <ConsoleForegroundColor.None_: -1>
Yellow: ConsoleForegroundColor # value = <ConsoleForegroundColor.Yellow: 33>