Skip to content

Commit 1bd90dd

Browse files
committed
attempt to manage cyclic references across multiple files
this is not working unfortunately (today); a similar approach may work in the future when superclass inherited type hints may work as well (probably python 3.13+) Signed-off-by: Federico M. Facca <federico.facca@zaphiro.ch>
1 parent cd22874 commit 1bd90dd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

modernpython/langPack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_class_location(class_name, class_map, version):
3737
# Check if the current class has a parent class
3838
if class_map[class_name].superClass():
3939
if class_map[class_name].superClass() in class_map:
40-
return "cimpy." + version + "." + class_map[class_name].superClass()
40+
return "modernpython." + version + "." + class_map[class_name].superClass()
4141
elif class_map[class_name].superClass() == "Base" or class_map[class_name].superClass() == None:
4242
return location(version)
4343
else:
@@ -53,7 +53,7 @@ def _compute_data_type(attribute):
5353

5454
if "range" in attribute:
5555
# return "'"+attribute["range"].split("#")[1]+"'"
56-
return attribute["range"].split("#")[1]
56+
return "'"+attribute["range"].split("#")[1]+"'"
5757
if "dataType" in attribute and "class_name" in attribute:
5858
# for whatever weird reason String is not created as class from CIMgen
5959
if is_primitive_class(attribute["class_name"]) or attribute["class_name"] == "String":
@@ -84,7 +84,7 @@ def _compute_data_type(attribute):
8484
if is_cim_data_type_class(attribute["class_name"]):
8585
return "float"
8686
# this is for example the case for 'StreetAddress.streetDetail'
87-
return attribute["dataType"].split("#")[1]
87+
return "'"+attribute["dataType"].split("#")[1]+"'"
8888

8989
def _ends_with_s(attribute_name):
9090
return attribute_name.endswith("s")

modernpython/templates/cimpy_class_template.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ from functools import cached_property
77
from typing import Optional, List
88
from pydantic import Field, field_validator
99
import uuid
10-
from pydantic.dataclasses import dataclass
10+
from datetime import date, datetime, time
11+
from pydantic.dataclasses import dataclass, rebuild_dataclass
1112
from .Base import DataclassConfig, Profile
1213
from .util import cyclic_references_validator
1314
from .{{sub_class_of}} import {{sub_class_of}}
14-
{{#setImports}}{{attributes}}{{/setImports}}
1515

1616
@dataclass(config=DataclassConfig)
1717
class {{class_name}}({{sub_class_of}}):
@@ -46,3 +46,7 @@ class {{class_name}}({{sub_class_of}}):
4646
where this element can be found.
4747
"""
4848
return { {{#class_origin}}Profile.{{origin}}, {{/class_origin}} }
49+
50+
{{#setImports}}{{attributes}}{{/setImports}}
51+
52+
rebuild_dataclass({{class_name}})

0 commit comments

Comments
 (0)