Skip to content

Commit 3b413b2

Browse files
committed
Test: Defaulted Native Enum Argument
1 parent 80a777e commit 3b413b2

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

tests/check-demo-stubs-generation.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ run_stubgen() {
6161
${NUMPY_FORMAT} \
6262
--ignore-invalid-expressions="\(anonymous namespace\)::(Enum|Unbound)|<demo\._bindings\.flawed_bindings\..*" \
6363
--enum-class-locations="ConsoleForegroundColor:demo._bindings.enum" \
64+
--enum-class-locations="NativeColor:demo._bindings.enum" \
6465
--print-value-comments \
6566
--print-safe-value-reprs="Foo\(\d+\)" \
6667
--exit-code

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ void bind_enum_module(py::module&&m) {
3535
.value("Red", NativeColor::Red)
3636
.value("Blue", NativeColor::Blue)
3737
.finalize();
38+
39+
// Regression: https://github.com/pybind/pybind11-stubgen/issues/304
40+
// Defaults referring to a py::native_enum must not be rendered in a form
41+
// that triggers a parent-package lookup at stub import time.
42+
m.def(
43+
"accept_defaulted_native_enum",
44+
[](const NativeColor &color) {},
45+
py::arg("color") = NativeColor::Red);
3846
#endif
3947
}

0 commit comments

Comments
 (0)