diff --git a/modernpython/primitive_header.py b/modernpython/primitive_header.py index 8fa95acc..c8e79e7d 100644 --- a/modernpython/primitive_header.py +++ b/modernpython/primitive_header.py @@ -3,4 +3,4 @@ from ..utils.profile import Profile from .enum import * -String = Primitive("String",str, [Profile.EQBD, Profile.OP, Profile.SSH, Profile.EQ, Profile.DY, Profile.DL, Profile.SV, Profile.SC, ]) \ No newline at end of file +String = Primitive(name="String",type=str, profiles=[Profile.EQBD, Profile.OP, Profile.SSH, Profile.EQ, Profile.DY, Profile.DL, Profile.SV, Profile.SC, ]) \ No newline at end of file diff --git a/modernpython/templates/cimdatatype_template.mustache b/modernpython/templates/cimdatatype_template.mustache index 6ca8c7e1..d2d553fe 100644 --- a/modernpython/templates/cimdatatype_template.mustache +++ b/modernpython/templates/cimdatatype_template.mustache @@ -3,7 +3,7 @@ Generated from the CGMES 3 files via cimgen: https://github.com/sogno-platform/cimgen """ -{{class_name}} = CIMDatatype("{{class_name}}", {{data_type}}, {{unit}}, {{multiplier}}, [{{#class_origin}}Profile.{{origin}},{{/class_origin}}]) +{{class_name}} = CIMDatatype(name="{{class_name}}", type={{data_type}}, symbol={{unit}}, multiplier={{multiplier}}, profiles=[{{#class_origin}}Profile.{{origin}},{{/class_origin}}]) """ {{{wrapped_class_comment}}} diff --git a/modernpython/templates/primitive_template.mustache b/modernpython/templates/primitive_template.mustache index 40a1e040..91282052 100644 --- a/modernpython/templates/primitive_template.mustache +++ b/modernpython/templates/primitive_template.mustache @@ -3,7 +3,7 @@ Generated from the CGMES 3 files via cimgen: https://github.com/sogno-platform/cimgen """ -{{class_name}} = Primitive("{{class_name}}", {{data_type}}, [{{#class_origin}}Profile.{{origin}}, {{/class_origin}}]) +{{class_name}} = Primitive(name="{{class_name}}", type={{data_type}}, profiles=[{{#class_origin}}Profile.{{origin}}, {{/class_origin}}]) """ {{{wrapped_class_comment}}} diff --git a/modernpython/utils/datatypes.py b/modernpython/utils/datatypes.py index b6709344..b14b2ee2 100644 --- a/modernpython/utils/datatypes.py +++ b/modernpython/utils/datatypes.py @@ -1,7 +1,5 @@ -import importlib -from dataclasses import Field, fields -from functools import cached_property -from typing import Any, TypeAlias, TypedDict +from pydantic import Field +from typing import List from .constants import NAMESPACES from pydantic.dataclasses import dataclass @@ -13,39 +11,13 @@ @dataclass(config=DataclassConfig) class Primitive: - def __init__(self, name: str, type, profiles: set[BaseProfile]): - self.name = name - self.type = type - self.profiles = profiles - - def get_name(self) -> str: - return self.name - - def get_type(self): - return self.type - - @cached_property - def namespace(self) -> str: - """Returns the namespace. By default, the namespace is the cim namespace for all resources. - Custom resources can override this. - """ - return NAMESPACES["cim"] - - @cached_property - def get_profiles(self) -> set[BaseProfile]: - return self.profiles + name: str = Field(frozen=True) + type: object = Field(frozen=True) + namespace: str = Field(frozen=True, default=NAMESPACES["cim"]) + profiles: List[BaseProfile] = Field(frozen=True) @dataclass(config=DataclassConfig) class CIMDatatype(Primitive): - - def __init__(self, - name: str, type, symbol: UnitSymbol, multiplier: UnitMultiplier, profiles: set[BaseProfile]): - super().__init__(name, type, profiles) - self.multiplier = multiplier - self.symbol = symbol - - def get_multiplier(self) -> UnitMultiplier: - return self.multiplier - - def get_symbol(self) -> UnitSymbol: - return self.symbol \ No newline at end of file + + multiplier: UnitMultiplier = Field(frozen=True) + symbol: UnitSymbol = Field(frozen=True)