From a8b6737e8beea59cfc6047619cd0ec436ffb2809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20V=2E=20Treider?= Date: Thu, 10 Oct 2024 12:07:06 +0200 Subject: [PATCH] fix typed instance apply classes --- .../data_classes/data_modeling/cdm/v1.py | 65 ++++++++++--------- .../data_classes/data_modeling/instances.py | 21 +++--- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/cognite/client/data_classes/data_modeling/cdm/v1.py b/cognite/client/data_classes/data_modeling/cdm/v1.py index e652bab6d..967e5bfa4 100644 --- a/cognite/client/data_classes/data_modeling/cdm/v1.py +++ b/cognite/client/data_classes/data_modeling/cdm/v1.py @@ -6,6 +6,7 @@ from cognite.client.data_classes.data_modeling import DirectRelationReference from cognite.client.data_classes.data_modeling.ids import ViewId from cognite.client.data_classes.data_modeling.instances import ( + NOT_SET, PropertyOptions, TypedEdge, TypedEdgeApply, @@ -87,7 +88,7 @@ def __init__( station_360: DirectRelationReference | tuple[str, str] | None = None, taken_at: datetime | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.translation_x = translation_x @@ -263,7 +264,7 @@ def __init__( revision_type: Literal["CAD", "Image360", "PointCloud"] | None = None, model_3d: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -385,7 +386,7 @@ def __init__( model_type: Literal["CAD", "Image360", "PointCloud"] | None = None, thumbnail: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -495,7 +496,7 @@ def __init__( aliases: list[str] | None = None, group_type: Literal["Station360"] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -602,7 +603,7 @@ def __init__( model_type: Literal["CAD", "Image360", "PointCloud"] | None = None, thumbnail: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -727,7 +728,7 @@ def __init__( z_min: float | None = None, z_max: float | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -857,7 +858,7 @@ def __init__( revision_type: Literal["CAD", "Image360", "PointCloud"] | None = None, model_3d: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.status = status @@ -975,7 +976,7 @@ def __init__( scale_y: float | None = None, scale_z: float | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.translation_x = translation_x @@ -1137,7 +1138,7 @@ def __init__( equipment: list[DirectRelationReference | tuple[str, str]] | None = None, time_series: list[DirectRelationReference | tuple[str, str]] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -1338,9 +1339,9 @@ def __init__( source_updated_user: str | None = None, parent: DirectRelationReference | tuple[str, str] | None = None, asset_class: DirectRelationReference | tuple[str, str] | None = None, - asset_type: DirectRelationReference | tuple[str, str] | None = None, + asset_type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.object_3d = DirectRelationReference.load(object_3d) if object_3d else None @@ -1504,7 +1505,7 @@ def __init__( code: str | None = None, standard: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -1618,7 +1619,7 @@ def __init__( standard: str | None = None, asset_class: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -1735,7 +1736,7 @@ def __init__( model_type: Literal["CAD", "Image360", "PointCloud"] | None = None, thumbnail: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -1859,7 +1860,7 @@ def __init__( tree_indexes: list[int] | None = None, sub_tree_sizes: list[int] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -1990,7 +1991,7 @@ def __init__( model_3d: DirectRelationReference | tuple[str, str] | None = None, revision_id: int | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.status = status @@ -2095,7 +2096,7 @@ def __init__( top: DirectRelationReference | tuple[str, str] | None = None, bottom: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.front = DirectRelationReference.load(front) if front else None @@ -2203,7 +2204,7 @@ def __init__( tags: list[str] | None = None, aliases: list[str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -2330,10 +2331,10 @@ def __init__( asset: DirectRelationReference | tuple[str, str] | None = None, serial_number: str | None = None, manufacturer: str | None = None, - equipment_type: DirectRelationReference | tuple[str, str] | None = None, + equipment_type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] files: list[DirectRelationReference | tuple[str, str]] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -2500,7 +2501,7 @@ def __init__( standard: str | None = None, standard_reference: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -2648,7 +2649,7 @@ def __init__( directory: str | None = None, category: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -2813,7 +2814,7 @@ def __init__( standard: str | None = None, standard_reference: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.code = code @@ -2930,7 +2931,7 @@ def __init__( model_type: Literal["CAD", "Image360", "PointCloud"] | None = None, thumbnail: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -3042,7 +3043,7 @@ def __init__( model_3d: DirectRelationReference | tuple[str, str] | None = None, revision_id: int | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.status = status @@ -3163,7 +3164,7 @@ def __init__( volume: list[float] | None = None, format_version: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -3299,7 +3300,7 @@ def __init__( scheduled_start_time: datetime | None = None, scheduled_end_time: datetime | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.start_time = start_time @@ -3401,7 +3402,7 @@ def __init__( source_system_version: str | None = None, manufacturer: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -3519,7 +3520,7 @@ def __init__( source_created_user: str | None = None, source_updated_user: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.source_id = source_id @@ -3665,7 +3666,7 @@ def __init__( assets: list[DirectRelationReference | tuple[str, str]] | None = None, equipment: list[DirectRelationReference | tuple[str, str]] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.is_step = is_step @@ -3836,7 +3837,7 @@ def __init__( source: str | None = None, source_reference: str | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.name = name @@ -3948,7 +3949,7 @@ def __init__( *, object_3d: DirectRelationReference | tuple[str, str] | None = None, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: TypedNodeApply.__init__(self, space, external_id, existing_version, type) self.object_3d = DirectRelationReference.load(object_3d) if object_3d else None diff --git a/cognite/client/data_classes/data_modeling/instances.py b/cognite/client/data_classes/data_modeling/instances.py index affa10124..2ebcf1b95 100644 --- a/cognite/client/data_classes/data_modeling/instances.py +++ b/cognite/client/data_classes/data_modeling/instances.py @@ -655,21 +655,16 @@ def as_apply(self) -> NodeApply: """ This is a convenience function for converting the read to a write node. - It makes the simplifying assumption that all properties are from the same view. Note that this - is not true in general. - Returns: NodeApply: A write node, NodeApply """ + sources = [NodeOrEdgeData(source=view_id, properties=props) for view_id, props in self.properties.items()] return NodeApply( space=self.space, external_id=self.external_id, existing_version=self.version, - sources=[ - NodeOrEdgeData(source=view_id, properties=properties) for view_id, properties in self.properties.items() - ] - or None, + sources=sources or None, type=self.type, ) @@ -1620,7 +1615,7 @@ def __init__( space: str, external_id: str, existing_version: int | None = None, - type: DirectRelationReference | tuple[str, str] | None = None, + type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment] ) -> None: super().__init__(space, external_id, existing_version, type=type) @@ -1749,7 +1744,15 @@ def properties(self) -> Properties: | TypedEdgeApply._base_properties() | TypedNode._base_properties() | TypedEdge._base_properties() -) | {"instance_type", "existing_version", "_InstanceApply__sources", "_Instance__properties", "_Instance__prop_lookup"} +) | { + "instance_type", + "existing_version", + "_InstanceApply__sources", + "_Instance__properties", + "_Instance__prop_lookup", + "_NodeApply__type", + "_NodeApply__type_was_set", +} class _PropertyValueSerializer: