Skip to content

Commit 192c24f

Browse files
committed
Fix: Print as String
1 parent 3b413b2 commit 192c24f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • pybind11_stubgen/parser/mixins

pybind11_stubgen/parser/mixins/fix.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,17 @@ def parse_value_str(self, value: str) -> Value | InvalidExpression:
11201120
continue
11211121
enum_class = self.parse_annotation_str(f"{prefix}.{enum_class_str}")
11221122
if isinstance(enum_class, ResolvedType):
1123-
return Value(repr=f"{enum_class.name}.{entry}", is_print_safe=True)
1123+
# Emit the default using the enum class's short path
1124+
# only. A parent-package-qualified form
1125+
# ``<pkg>.<subpkg>.<Enum>.<Member>`` is evaluated at
1126+
# stub-import time and can traverse a partially-
1127+
# initialized parent package, raising a circular-
1128+
# import ``AttributeError`` (issue #304). The
1129+
# argument's type annotation is already rendered in
1130+
# the same short form, so the enum class is in scope.
1131+
return Value(
1132+
repr=f"{enum_class_str}.{entry}", is_print_safe=True
1133+
)
11241134
return super().parse_value_str(value)
11251135

11261136
def report_error(self, error: ParserError) -> None:

0 commit comments

Comments
 (0)