Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹Exclude enums from circular reference Workaround #101

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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