diff --git a/src/bo4e_generator/imports.py b/src/bo4e_generator/imports.py index 6cc5ce1..727c0c4 100644 --- a/src/bo4e_generator/imports.py +++ b/src/bo4e_generator/imports.py @@ -18,9 +18,9 @@ def monkey_patch_imports(namespace: dict[str, SchemaMetadata]): Overwrites the behaviour how imports are rendered. They are not going through jinja templates. They Imports class has a __str__ method, which we will overwrite here. """ - namespace = {k: v for k, v in namespace.items() if k not in ("Typ", "Landescode")} + namespace = {k: v for k, v in namespace.items() if v.module_path[0] != "enum"} # "Typ" and "Landescode" must not be wrapped inside the "if TYPE_CHECKING" block because they are used explicitly - # to set default values. + # to set default values. Generally, enums can be excluded since they cannot cause circular reference issues. import_type_checking = Import.from_full_path("typing.TYPE_CHECKING") # pylint: disable=missing-function-docstring diff --git a/src/bo4e_generator/parser.py b/src/bo4e_generator/parser.py index 71f910c..6b39366 100644 --- a/src/bo4e_generator/parser.py +++ b/src/bo4e_generator/parser.py @@ -91,7 +91,7 @@ class DataTypeWithForwardRef(self.data_type): def type_hint(self) -> str: """Return the type hint for the data type.""" type_ = super().type_hint - if self.reference and type_ in namespace: + if self.reference and type_ in namespace and namespace[type_].module_path[0] != "enum": type_ = f'"{type_}"' return type_