Skip to content

Commit a93f89e

Browse files
authored
Fix enum value regexp (#153)
Fixes #152
1 parent 400f557 commit a93f89e

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
Changelog
22
=========
33

4+
Version 2.2.1 (Sep 23, 2023)
5+
--------------------------
6+
Changes:
7+
- 🐛 fix: Missing `-?` in eum representation regex
8+
49

510
Version 2.2.1 (Sep 23, 2023)
611
--------------------------
712
Changes:
8-
- 📝 Updater `--print-invalid-expressions-as-is` description
13+
- 📝 Update `--print-invalid-expressions-as-is` description
914

1015
Version 2.2 (Sep 20, 2023)
1116
--------------------------

pybind11_stubgen/parser/mixins/fix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,8 @@ def parse_value_str(self, value: str) -> Value | InvalidExpression:
779779

780780

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

785786
def __init__(self):

tests/demo-lib/include/demo/sublibA/ConsoleColors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ enum class ConsoleForegroundColor {
55
Green = 32,
66
Yellow = 33,
77
Blue = 34,
8-
Magenta = 35
8+
Magenta = 35,
9+
None_ = -1
910
};
1011

1112
enum ConsoleBackgroundColor {

tests/py-demo/bindings/src/modules/enum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ void bind_enum_module(py::module_&&m) {
99
.value("Yellow", demo::sublibA::ConsoleForegroundColor::Yellow)
1010
.value("Blue", demo::sublibA::ConsoleForegroundColor::Blue)
1111
.value("Magenta", demo::sublibA::ConsoleForegroundColor::Magenta)
12+
.value("None_", demo::sublibA::ConsoleForegroundColor::None_)
1213
.export_values();
1314

1415
m.def(
1516
"accept_defaulted_enum",
1617
[](const demo::sublibA::ConsoleForegroundColor &color) {},
17-
py::arg("color") = demo::sublibA::ConsoleForegroundColor::Blue);
18+
py::arg("color") = demo::sublibA::ConsoleForegroundColor::None_);
1819
}

tests/stubs/python-3.11/pybind11-master/demo/_bindings/enum.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __all__ = [
77
"ConsoleForegroundColor",
88
"Green",
99
"Magenta",
10+
"None_",
1011
"Yellow",
1112
"accept_defaulted_enum",
1213
]
@@ -22,6 +23,8 @@ class ConsoleForegroundColor:
2223
Blue
2324
2425
Magenta
26+
27+
None_
2528
"""
2629

2730
Blue: typing.ClassVar[
@@ -33,12 +36,15 @@ class ConsoleForegroundColor:
3336
Magenta: typing.ClassVar[
3437
ConsoleForegroundColor
3538
] # value = <ConsoleForegroundColor.Magenta: 35>
39+
None_: typing.ClassVar[
40+
ConsoleForegroundColor
41+
] # value = <ConsoleForegroundColor.None_: -1>
3642
Yellow: typing.ClassVar[
3743
ConsoleForegroundColor
3844
] # value = <ConsoleForegroundColor.Yellow: 33>
3945
__members__: typing.ClassVar[
4046
dict[str, ConsoleForegroundColor]
41-
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}
47+
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>, 'None_': <ConsoleForegroundColor.None_: -1>}
4248
def __eq__(self, other: typing.Any) -> bool: ...
4349
def __getstate__(self) -> int: ...
4450
def __hash__(self) -> int: ...
@@ -55,10 +61,11 @@ class ConsoleForegroundColor:
5561
def value(self) -> int: ...
5662

5763
def accept_defaulted_enum(
58-
color: ConsoleForegroundColor = ConsoleForegroundColor.Blue,
64+
color: ConsoleForegroundColor = ConsoleForegroundColor.None_,
5965
) -> None: ...
6066

6167
Blue: ConsoleForegroundColor # value = <ConsoleForegroundColor.Blue: 34>
6268
Green: ConsoleForegroundColor # value = <ConsoleForegroundColor.Green: 32>
6369
Magenta: ConsoleForegroundColor # value = <ConsoleForegroundColor.Magenta: 35>
70+
None_: ConsoleForegroundColor # value = <ConsoleForegroundColor.None_: -1>
6471
Yellow: ConsoleForegroundColor # value = <ConsoleForegroundColor.Yellow: 33>

tests/stubs/python-3.7/pybind11-master/demo/_bindings/enum.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __all__ = [
77
"ConsoleForegroundColor",
88
"Green",
99
"Magenta",
10+
"None_",
1011
"Yellow",
1112
"accept_defaulted_enum",
1213
]
@@ -22,6 +23,8 @@ class ConsoleForegroundColor:
2223
Blue
2324
2425
Magenta
26+
27+
None_
2528
"""
2629

2730
Blue: typing.ClassVar[
@@ -33,12 +36,15 @@ class ConsoleForegroundColor:
3336
Magenta: typing.ClassVar[
3437
ConsoleForegroundColor
3538
] # value = <ConsoleForegroundColor.Magenta: 35>
39+
None_: typing.ClassVar[
40+
ConsoleForegroundColor
41+
] # value = <ConsoleForegroundColor.None_: -1>
3642
Yellow: typing.ClassVar[
3743
ConsoleForegroundColor
3844
] # value = <ConsoleForegroundColor.Yellow: 33>
3945
__members__: typing.ClassVar[
4046
dict[str, ConsoleForegroundColor]
41-
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}
47+
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>, 'None_': <ConsoleForegroundColor.None_: -1>}
4248
def __eq__(self, other: typing.Any) -> bool: ...
4349
def __getstate__(self) -> int: ...
4450
def __hash__(self) -> int: ...
@@ -55,10 +61,11 @@ class ConsoleForegroundColor:
5561
def value(self) -> int: ...
5662

5763
def accept_defaulted_enum(
58-
color: ConsoleForegroundColor = ConsoleForegroundColor.Blue,
64+
color: ConsoleForegroundColor = ConsoleForegroundColor.None_,
5965
) -> None: ...
6066

6167
Blue: ConsoleForegroundColor # value = <ConsoleForegroundColor.Blue: 34>
6268
Green: ConsoleForegroundColor # value = <ConsoleForegroundColor.Green: 32>
6369
Magenta: ConsoleForegroundColor # value = <ConsoleForegroundColor.Magenta: 35>
70+
None_: ConsoleForegroundColor # value = <ConsoleForegroundColor.None_: -1>
6471
Yellow: ConsoleForegroundColor # value = <ConsoleForegroundColor.Yellow: 33>

tests/stubs/python-3.8/pybind11-master/demo/_bindings/enum.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ __all__ = [
77
"ConsoleForegroundColor",
88
"Green",
99
"Magenta",
10+
"None_",
1011
"Yellow",
1112
"accept_defaulted_enum",
1213
]
@@ -22,6 +23,8 @@ class ConsoleForegroundColor:
2223
Blue
2324
2425
Magenta
26+
27+
None_
2528
"""
2629

2730
Blue: typing.ClassVar[
@@ -33,12 +36,15 @@ class ConsoleForegroundColor:
3336
Magenta: typing.ClassVar[
3437
ConsoleForegroundColor
3538
] # value = <ConsoleForegroundColor.Magenta: 35>
39+
None_: typing.ClassVar[
40+
ConsoleForegroundColor
41+
] # value = <ConsoleForegroundColor.None_: -1>
3642
Yellow: typing.ClassVar[
3743
ConsoleForegroundColor
3844
] # value = <ConsoleForegroundColor.Yellow: 33>
3945
__members__: typing.ClassVar[
4046
dict[str, ConsoleForegroundColor]
41-
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}
47+
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>, 'None_': <ConsoleForegroundColor.None_: -1>}
4248
def __eq__(self, other: typing.Any) -> bool: ...
4349
def __getstate__(self) -> int: ...
4450
def __hash__(self) -> int: ...
@@ -55,10 +61,11 @@ class ConsoleForegroundColor:
5561
def value(self) -> int: ...
5662

5763
def accept_defaulted_enum(
58-
color: ConsoleForegroundColor = ConsoleForegroundColor.Blue,
64+
color: ConsoleForegroundColor = ConsoleForegroundColor.None_,
5965
) -> None: ...
6066

6167
Blue: ConsoleForegroundColor # value = <ConsoleForegroundColor.Blue: 34>
6268
Green: ConsoleForegroundColor # value = <ConsoleForegroundColor.Green: 32>
6369
Magenta: ConsoleForegroundColor # value = <ConsoleForegroundColor.Magenta: 35>
70+
None_: ConsoleForegroundColor # value = <ConsoleForegroundColor.None_: -1>
6471
Yellow: ConsoleForegroundColor # value = <ConsoleForegroundColor.Yellow: 33>

0 commit comments

Comments
 (0)