Skip to content

Commit 8e69b43

Browse files
authored
Sequence not String (#1574)
1 parent c83e41e commit 8e69b43

38 files changed

+301
-244
lines changed

cognite/client/_api/assets.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
process_asset_subtree_ids,
6565
process_data_set_ids,
6666
)
67+
from cognite.client.utils.useful_types import SequenceNotStr
6768

6869
if TYPE_CHECKING:
6970
from concurrent.futures import Future, ThreadPoolExecutor
@@ -105,12 +106,12 @@ def __call__(
105106
chunk_size: int | None = None,
106107
name: str | None = None,
107108
parent_ids: Sequence[int] | None = None,
108-
parent_external_ids: Sequence[str] | None = None,
109+
parent_external_ids: SequenceNotStr[str] | None = None,
109110
asset_subtree_ids: int | Sequence[int] | None = None,
110-
asset_subtree_external_ids: str | Sequence[str] | None = None,
111+
asset_subtree_external_ids: str | SequenceNotStr[str] | None = None,
111112
metadata: dict[str, str] | None = None,
112113
data_set_ids: int | Sequence[int] | None = None,
113-
data_set_external_ids: str | Sequence[str] | None = None,
114+
data_set_external_ids: str | SequenceNotStr[str] | None = None,
114115
labels: LabelFilter | None = None,
115116
geo_location: GeoLocationFilter | None = None,
116117
source: str | None = None,
@@ -130,12 +131,12 @@ def __call__(
130131
chunk_size (int | None): Number of assets to return in each chunk. Defaults to yielding one asset a time.
131132
name (str | None): Name of asset. Often referred to as tag.
132133
parent_ids (Sequence[int] | None): Return only the direct descendants of the specified assets.
133-
parent_external_ids (Sequence[str] | None): Return only the direct descendants of the specified assets.
134+
parent_external_ids (SequenceNotStr[str] | None): Return only the direct descendants of the specified assets.
134135
asset_subtree_ids (int | Sequence[int] | None): Asset subtree id or list of asset subtree ids to filter on.
135-
asset_subtree_external_ids (str | Sequence[str] | None): Asset subtree external id or list of asset subtree external ids to filter on.
136+
asset_subtree_external_ids (str | SequenceNotStr[str] | None): Asset subtree external id or list of asset subtree external ids to filter on.
136137
metadata (dict[str, str] | None): Custom, application specific metadata. String key -> String value
137138
data_set_ids (int | Sequence[int] | None): Return only assets in the specified data set(s) with this id / these ids.
138-
data_set_external_ids (str | Sequence[str] | None): Return only assets in the specified data set(s) with this external id / these external ids.
139+
data_set_external_ids (str | SequenceNotStr[str] | None): Return only assets in the specified data set(s) with this external id / these external ids.
139140
labels (LabelFilter | None): Return only the assets matching the specified label.
140141
geo_location (GeoLocationFilter | None): Only include files matching the specified geographic relation.
141142
source (str | None): The source of this asset
@@ -221,14 +222,14 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Ass
221222
def retrieve_multiple(
222223
self,
223224
ids: Sequence[int] | None = None,
224-
external_ids: Sequence[str] | None = None,
225+
external_ids: SequenceNotStr[str] | None = None,
225226
ignore_unknown_ids: bool = False,
226227
) -> AssetList:
227228
"""`Retrieve multiple assets by id. <https://developer.cognite.com/api#tag/Assets/operation/byIdsAssets>`_
228229
229230
Args:
230231
ids (Sequence[int] | None): IDs
231-
external_ids (Sequence[str] | None): External IDs
232+
external_ids (SequenceNotStr[str] | None): External IDs
232233
ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception.
233234
234235
Returns:
@@ -682,15 +683,15 @@ def create_hierarchy(
682683
def delete(
683684
self,
684685
id: int | Sequence[int] | None = None,
685-
external_id: str | Sequence[str] | None = None,
686+
external_id: str | SequenceNotStr[str] | None = None,
686687
recursive: bool = False,
687688
ignore_unknown_ids: bool = False,
688689
) -> None:
689690
"""`Delete one or more assets <https://developer.cognite.com/api#tag/Assets/operation/deleteAssets>`_
690691
691692
Args:
692693
id (int | Sequence[int] | None): Id or list of ids
693-
external_id (str | Sequence[str] | None): External ID or list of external ids
694+
external_id (str | SequenceNotStr[str] | None): External ID or list of external ids
694695
recursive (bool): Recursively delete whole asset subtrees under given ids. Defaults to False.
695696
ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception.
696697
@@ -995,11 +996,11 @@ def list(
995996
self,
996997
name: str | None = None,
997998
parent_ids: Sequence[int] | None = None,
998-
parent_external_ids: Sequence[str] | None = None,
999+
parent_external_ids: SequenceNotStr[str] | None = None,
9991000
asset_subtree_ids: int | Sequence[int] | None = None,
1000-
asset_subtree_external_ids: str | Sequence[str] | None = None,
1001+
asset_subtree_external_ids: str | SequenceNotStr[str] | None = None,
10011002
data_set_ids: int | Sequence[int] | None = None,
1002-
data_set_external_ids: str | Sequence[str] | None = None,
1003+
data_set_external_ids: str | SequenceNotStr[str] | None = None,
10031004
labels: LabelFilter | None = None,
10041005
geo_location: GeoLocationFilter | None = None,
10051006
metadata: dict[str, str] | None = None,
@@ -1017,11 +1018,11 @@ def list(
10171018
Args:
10181019
name (str | None): Name of asset. Often referred to as tag.
10191020
parent_ids (Sequence[int] | None): Return only the direct descendants of the specified assets.
1020-
parent_external_ids (Sequence[str] | None): Return only the direct descendants of the specified assets.
1021+
parent_external_ids (SequenceNotStr[str] | None): Return only the direct descendants of the specified assets.
10211022
asset_subtree_ids (int | Sequence[int] | None): Asset subtree id or list of asset subtree ids to filter on.
1022-
asset_subtree_external_ids (str | Sequence[str] | None): Asset subtree external id or list of asset subtree external ids to filter on.
1023+
asset_subtree_external_ids (str | SequenceNotStr[str] | None): Asset subtree external id or list of asset subtree external ids to filter on.
10231024
data_set_ids (int | Sequence[int] | None): Return only assets in the specified data set(s) with this id / these ids.
1024-
data_set_external_ids (str | Sequence[str] | None): Return only assets in the specified data set(s) with this external id / these external ids.
1025+
data_set_external_ids (str | SequenceNotStr[str] | None): Return only assets in the specified data set(s) with this external id / these external ids.
10251026
labels (LabelFilter | None): Return only the assets matching the specified label filter.
10261027
geo_location (GeoLocationFilter | None): Only include files matching the specified geographic relation.
10271028
metadata (dict[str, str] | None): Custom, application specific metadata. String key -> String value.

cognite/client/_api/data_modeling/instances.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def histogram(
858858
histograms: Histogram,
859859
instance_type: Literal["node", "edge"] = "node",
860860
query: str | None = None,
861-
properties: Sequence[str] | None = None,
861+
properties: SequenceNotStr[str] | None = None,
862862
filter: Filter | None = None,
863863
limit: int = DEFAULT_LIMIT_READ,
864864
) -> HistogramValue:
@@ -871,7 +871,7 @@ def histogram(
871871
histograms: Sequence[Histogram],
872872
instance_type: Literal["node", "edge"] = "node",
873873
query: str | None = None,
874-
properties: Sequence[str] | None = None,
874+
properties: SequenceNotStr[str] | None = None,
875875
filter: Filter | None = None,
876876
limit: int = DEFAULT_LIMIT_READ,
877877
) -> list[HistogramValue]:
@@ -883,7 +883,7 @@ def histogram(
883883
histograms: Histogram | Sequence[Histogram],
884884
instance_type: Literal["node", "edge"] = "node",
885885
query: str | None = None,
886-
properties: Sequence[str] | None = None,
886+
properties: SequenceNotStr[str] | None = None,
887887
filter: Filter | None = None,
888888
limit: int = DEFAULT_LIMIT_READ,
889889
) -> HistogramValue | list[HistogramValue]:
@@ -894,7 +894,7 @@ def histogram(
894894
histograms (Histogram | Sequence[Histogram]): The properties to aggregate over.
895895
instance_type (Literal["node", "edge"]): Whether to search for nodes or edges.
896896
query (str | None): Query string that will be parsed and used for search.
897-
properties (Sequence[str] | None): Optional array of properties you want to search through. If you do not specify one or more properties, the service will search all text fields within the view.
897+
properties (SequenceNotStr[str] | None): Optional array of properties you want to search through. If you do not specify one or more properties, the service will search all text fields within the view.
898898
filter (Filter | None): Advanced filtering of instances.
899899
limit (int): Maximum number of instances to return. Defaults to 25.
900900

cognite/client/_api/data_sets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
TimestampRange,
1515
)
1616
from cognite.client.utils._identifier import IdentifierSequence
17+
from cognite.client.utils.useful_types import SequenceNotStr
1718

1819
if TYPE_CHECKING:
1920
from cognite.client import CogniteClient
@@ -137,14 +138,14 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Dat
137138
def retrieve_multiple(
138139
self,
139140
ids: Sequence[int] | None = None,
140-
external_ids: Sequence[str] | None = None,
141+
external_ids: SequenceNotStr[str] | None = None,
141142
ignore_unknown_ids: bool = False,
142143
) -> DataSetList:
143144
"""`Retrieve multiple data sets by id. <https://developer.cognite.com/api#tag/Data-sets/operation/getDataSets>`_
144145
145146
Args:
146147
ids (Sequence[int] | None): IDs
147-
external_ids (Sequence[str] | None): External IDs
148+
external_ids (SequenceNotStr[str] | None): External IDs
148149
ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception.
149150
150151
Returns:

cognite/client/_api/datapoint_tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
time_ago_to_ms,
4747
timestamp_to_ms,
4848
)
49+
from cognite.client.utils.useful_types import SequenceNotStr
4950

5051
if not import_legacy_protobuf():
5152
from cognite.client._proto.data_point_list_response_pb2 import DataPointListItem
@@ -79,7 +80,7 @@
7980

8081
RawDatapointValue = Union[float, str]
8182
DatapointsId = Union[None, int, Dict[str, Any], Sequence[Union[int, Dict[str, Any]]]]
82-
DatapointsExternalId = Union[None, str, Dict[str, Any], Sequence[Union[str, Dict[str, Any]]]]
83+
DatapointsExternalId = Union[None, str, Dict[str, Any], SequenceNotStr[Union[str, Dict[str, Any]]]]
8384

8485

8586
class CustomDatapointsQuery(TypedDict, total=False):

cognite/client/_api/datapoints.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
validate_timezone,
7171
)
7272
from cognite.client.utils._validation import assert_type, validate_user_input_dict_with_identifier
73+
from cognite.client.utils.useful_types import SequenceNotStr
7374

7475
if not import_legacy_protobuf():
7576
from cognite.client._proto.data_point_list_response_pb2 import DataPointListItem, DataPointListResponse
@@ -562,7 +563,7 @@ def retrieve(
562563
self,
563564
*,
564565
id: None | int | dict[str, Any] | Sequence[int | dict[str, Any]] = None,
565-
external_id: None | str | dict[str, Any] | Sequence[str | dict[str, Any]] = None,
566+
external_id: None | str | dict[str, Any] | SequenceNotStr[str | dict[str, Any]] = None,
566567
start: int | str | datetime | None = None,
567568
end: int | str | datetime | None = None,
568569
aggregates: Aggregate | str | list[Aggregate | str] | None = None,
@@ -586,7 +587,7 @@ def retrieve(
586587
587588
Args:
588589
id (None | int | dict[str, Any] | Sequence[int | dict[str, Any]]): Id, dict (with id) or (mixed) sequence of these. See examples below.
589-
external_id (None | str | dict[str, Any] | Sequence[str | dict[str, Any]]): External id, dict (with external id) or (mixed) sequence of these. See examples below.
590+
external_id (None | str | dict[str, Any] | SequenceNotStr[str | dict[str, Any]]): External id, dict (with external id) or (mixed) sequence of these. See examples below.
590591
start (int | str | datetime | None): Inclusive start. Default: 1970-01-01 UTC.
591592
end (int | str | datetime | None): Exclusive end. Default: "now"
592593
aggregates (Aggregate | str | list[Aggregate | str] | None): Single aggregate or list of aggregates to retrieve. Default: None (raw datapoints returned)
@@ -769,7 +770,7 @@ def retrieve_arrays(
769770
self,
770771
*,
771772
id: None | int | dict[str, Any] | Sequence[int | dict[str, Any]] = None,
772-
external_id: None | str | dict[str, Any] | Sequence[str | dict[str, Any]] = None,
773+
external_id: None | str | dict[str, Any] | SequenceNotStr[str | dict[str, Any]] = None,
773774
start: int | str | datetime | None = None,
774775
end: int | str | datetime | None = None,
775776
aggregates: Aggregate | str | list[Aggregate | str] | None = None,
@@ -786,7 +787,7 @@ def retrieve_arrays(
786787
787788
Args:
788789
id (None | int | dict[str, Any] | Sequence[int | dict[str, Any]]): Id, dict (with id) or (mixed) sequence of these. See examples below.
789-
external_id (None | str | dict[str, Any] | Sequence[str | dict[str, Any]]): External id, dict (with external id) or (mixed) sequence of these. See examples below.
790+
external_id (None | str | dict[str, Any] | SequenceNotStr[str | dict[str, Any]]): External id, dict (with external id) or (mixed) sequence of these. See examples below.
790791
start (int | str | datetime | None): Inclusive start. Default: 1970-01-01 UTC.
791792
end (int | str | datetime | None): Exclusive end. Default: "now"
792793
aggregates (Aggregate | str | list[Aggregate | str] | None): Single aggregate or list of aggregates to retrieve. Default: None (raw datapoints returned)
@@ -872,7 +873,7 @@ def retrieve_dataframe(
872873
self,
873874
*,
874875
id: None | int | dict[str, Any] | Sequence[int | dict[str, Any]] = None,
875-
external_id: None | str | dict[str, Any] | Sequence[str | dict[str, Any]] = None,
876+
external_id: None | str | dict[str, Any] | SequenceNotStr[str | dict[str, Any]] = None,
876877
start: int | str | datetime | None = None,
877878
end: int | str | datetime | None = None,
878879
aggregates: Aggregate | str | list[Aggregate | str] | None = None,
@@ -893,7 +894,7 @@ def retrieve_dataframe(
893894
894895
Args:
895896
id (None | int | dict[str, Any] | Sequence[int | dict[str, Any]]): Id, dict (with id) or (mixed) sequence of these. See examples below.
896-
external_id (None | str | dict[str, Any] | Sequence[str | dict[str, Any]]): External id, dict (with external id) or (mixed) sequence of these. See examples below.
897+
external_id (None | str | dict[str, Any] | SequenceNotStr[str | dict[str, Any]]): External id, dict (with external id) or (mixed) sequence of these. See examples below.
897898
start (int | str | datetime | None): Inclusive start. Default: 1970-01-01 UTC.
898899
end (int | str | datetime | None): Exclusive end. Default: "now"
899900
aggregates (Aggregate | str | list[Aggregate | str] | None): Single aggregate or list of aggregates to retrieve. Default: None (raw datapoints returned)
@@ -1004,7 +1005,7 @@ def retrieve_dataframe_in_tz(
10041005
self,
10051006
*,
10061007
id: int | Sequence[int] | None = None,
1007-
external_id: str | Sequence[str] | None = None,
1008+
external_id: str | SequenceNotStr[str] | None = None,
10081009
start: datetime,
10091010
end: datetime,
10101011
aggregates: Aggregate | str | Sequence[Aggregate | str] | None = None,
@@ -1041,7 +1042,7 @@ def retrieve_dataframe_in_tz(
10411042
10421043
Args:
10431044
id (int | Sequence[int] | None): ID or list of IDs.
1044-
external_id (str | Sequence[str] | None): External ID or list of External IDs.
1045+
external_id (str | SequenceNotStr[str] | None): External ID or list of External IDs.
10451046
start (datetime): Inclusive start, must be time zone aware.
10461047
end (datetime): Exclusive end, must be time zone aware and have the same time zone as start.
10471048
aggregates (Aggregate | str | Sequence[Aggregate | str] | None): Single aggregate or list of aggregates to retrieve. Default: None (raw datapoints returned)
@@ -1594,7 +1595,7 @@ def __init__(
15941595
self.dps_client = dps_client
15951596

15961597
parsed_ids = cast(Union[None, int, Sequence[int]], self._parse_user_input(id, "id"))
1597-
parsed_xids = cast(Union[None, str, Sequence[str]], self._parse_user_input(external_id, "external_id"))
1598+
parsed_xids = cast(Union[None, str, SequenceNotStr[str]], self._parse_user_input(external_id, "external_id"))
15981599
self._is_singleton = IdentifierSequence.load(parsed_ids, parsed_xids).is_singleton()
15991600
self._all_identifiers = self._prepare_requests(parsed_ids, parsed_xids)
16001601

@@ -1638,7 +1639,7 @@ def _parse_user_input(
16381639
return user_input
16391640

16401641
def _prepare_requests(
1641-
self, parsed_ids: None | int | Sequence[int], parsed_xids: None | str | Sequence[str]
1642+
self, parsed_ids: None | int | Sequence[int], parsed_xids: None | str | SequenceNotStr[str]
16421643
) -> list[dict]:
16431644
all_ids, all_xids = [], []
16441645
if parsed_ids is not None:

cognite/client/_api/datapoints_subscriptions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Iterator, Sequence
3+
from typing import TYPE_CHECKING, Iterator
44

55
from cognite.client._api_client import APIClient
66
from cognite.client._constants import DEFAULT_LIMIT_READ
@@ -17,6 +17,7 @@
1717
)
1818
from cognite.client.utils._experimental import FeaturePreviewWarning
1919
from cognite.client.utils._identifier import IdentifierSequence
20+
from cognite.client.utils.useful_types import SequenceNotStr
2021

2122
if TYPE_CHECKING:
2223
from cognite.client import ClientConfig, CogniteClient
@@ -78,11 +79,11 @@ def create(self, subscription: DataPointSubscriptionWrite) -> DatapointSubscript
7879
input_resource_cls=DataPointSubscriptionWrite,
7980
)
8081

81-
def delete(self, external_id: str | Sequence[str], ignore_unknown_ids: bool = False) -> None:
82+
def delete(self, external_id: str | SequenceNotStr[str], ignore_unknown_ids: bool = False) -> None:
8283
"""`Delete subscription(s). This operation cannot be undone. <https://pr-2221.specs.preview.cogniteapp.com/20230101-beta.json.html#tag/Data-point-subscriptions/operation/deleteSubscriptions>`_
8384
8485
Args:
85-
external_id (str | Sequence[str]): External ID or list of external IDs of subscriptions to delete.
86+
external_id (str | SequenceNotStr[str]): External ID or list of external IDs of subscriptions to delete.
8687
ignore_unknown_ids (bool): Whether to ignore IDs and external IDs that are not found rather than throw an exception.
8788
8889
Examples:

0 commit comments

Comments
 (0)