Skip to content

Commit

Permalink
fix data type annotation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 committed Nov 27, 2023
1 parent c67d0d4 commit 053f04f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 40 deletions.
2 changes: 1 addition & 1 deletion modernpython/primitive_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ])
String = Primitive(name="String",type=str, profiles=[Profile.EQBD, Profile.OP, Profile.SSH, Profile.EQ, Profile.DY, Profile.DL, Profile.SV, Profile.SC, ])
2 changes: 1 addition & 1 deletion modernpython/templates/cimdatatype_template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}
Expand Down
2 changes: 1 addition & 1 deletion modernpython/templates/primitive_template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}
Expand Down
46 changes: 9 additions & 37 deletions modernpython/utils/datatypes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

multiplier: UnitMultiplier = Field(frozen=True)
symbol: UnitSymbol = Field(frozen=True)

0 comments on commit 053f04f

Please sign in to comment.