-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Milestone
Description
PR#198 introduces a pydantic model for CGNSNode but:
- it's not used anywhere (we are not instantiating
CGNSNodeobjects likenode = CGNSNode(name="node", value=, ...) - and we are still type hinting functions with this type
What could be done:
- properly use this object in functions that use in and out
CGNSNode at the same time, define pydantic models for other types ((let's keep this for another issue)Scalar,Field, ...)
Optional: we can also eventually define a constructor that accepts a list so that we can easily convert a pycgns "node" to a pydantic CGNSNode:
class CGNSNode(BaseModel):
name: str
value: Optional[Any] = None
children: list["CGNSNode"]
label: str
@model_validator(mode="before")
@classmethod
def from_list(cls, data: Any) -> Any:
# If the input is already a dict, let Pydantic handle it
if isinstance(data, dict):
return data
# If the input is a list, convert it
if isinstance(data, list) and len(data) == 4:
name, value, children, label = data
return {
"name": name,
"value": value,
"children": children,
"label": label,
}
return dataThis gives access to a simple constructor: node = CGNSNode(base_node) where base_node would be a CGNS node in raw format (list) given by pyCGNS.
Reactions are currently unavailable