Skip to content

Commit

Permalink
fix typed instance apply classes
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Oct 10, 2024
1 parent 2e03e05 commit a8b6737
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
65 changes: 33 additions & 32 deletions cognite/client/data_classes/data_modeling/cdm/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions cognite/client/data_classes/data_modeling/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a8b6737

Please sign in to comment.