Skip to content

Commit

Permalink
🩹Exclude enums from circular reference Workaround (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-haffi authored Jul 30, 2024
1 parent f17a391 commit 62db8f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/bo4e_generator/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bo4e_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down

0 comments on commit 62db8f7

Please sign in to comment.