Skip to content

Commit

Permalink
mypy doesnt understand list, wtf
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Aug 22, 2023
1 parent cba26a1 commit ec38b45
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
7 changes: 5 additions & 2 deletions cognite/client/_api/annotations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from copy import deepcopy
from typing import Any, Literal, Sequence, overload
from typing import TYPE_CHECKING, Any, Literal, Sequence, overload

from cognite.client._api_client import APIClient
from cognite.client._constants import LIST_LIMIT_DEFAULT
Expand All @@ -13,6 +13,9 @@
from cognite.client.utils._identifier import IdentifierSequence
from cognite.client.utils._text import to_camel_case

if TYPE_CHECKING:
import builtins


class AnnotationsAPI(APIClient):
_RESOURCE_PATH = "/annotations"
Expand Down Expand Up @@ -110,7 +113,7 @@ def list(self, filter: AnnotationFilter | dict, limit: int = LIST_LIMIT_DEFAULT)
def _convert_resource_to_patch_object(
cls,
resource: CogniteResource,
update_attributes: list[PropertySpec],
update_attributes: builtins.list[PropertySpec],
mode: Literal["replace_ignore_null", "patch", "replace"] = "replace_ignore_null",
) -> dict[str, dict[str, dict]]:
if not isinstance(resource, Annotation):
Expand Down
9 changes: 5 additions & 4 deletions cognite/client/_api/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from cognite.client.utils._validation import process_asset_subtree_ids, process_data_set_ids

if TYPE_CHECKING:
import builtins
from concurrent.futures import Future

from cognite.client.utils._priority_tpe import PriorityThreadPoolExecutor
Expand Down Expand Up @@ -316,14 +317,14 @@ def list(
partitions=partitions,
)

def aggregate(self, filter: AssetFilter | dict | None = None) -> list[AssetAggregate]:
def aggregate(self, filter: AssetFilter | dict | None = None) -> builtins.list[AssetAggregate]:
"""`Aggregate assets <https://developer.cognite.com/api#tag/Assets/operation/aggregateAssets>`_
Args:
filter (AssetFilter | dict | None): Filter on assets filter with exact match
Returns:
list[AssetAggregate]: List of asset aggregates
builtins.list[AssetAggregate]: List of asset aggregates
Examples:
Expand Down Expand Up @@ -777,15 +778,15 @@ def retrieve_subtree(
subtree = self._get_asset_subtree([asset], current_depth=0, depth=depth)
return AssetList(subtree, self._cognite_client)

def _get_asset_subtree(self, assets: list, current_depth: int, depth: int | None) -> list:
def _get_asset_subtree(self, assets: builtins.list, current_depth: int, depth: int | None) -> builtins.list:
subtree = assets
if depth is None or current_depth < depth:
children = self._get_children(assets)
if children:
subtree.extend(self._get_asset_subtree(children, current_depth + 1, depth))
return subtree

def _get_children(self, assets: list) -> list:
def _get_children(self, assets: builtins.list) -> builtins.list:
ids = [a.id for a in assets]
tasks = []
chunk_size = 100
Expand Down
6 changes: 4 additions & 2 deletions cognite/client/_api/data_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from cognite.client.utils._identifier import IdentifierSequence

if TYPE_CHECKING:
import builtins

from cognite.client import CogniteClient
from cognite.client.config import ClientConfig

Expand Down Expand Up @@ -210,14 +212,14 @@ def list(
).dump(camel_case=True)
return self._list(list_cls=DataSetList, resource_cls=DataSet, method="POST", limit=limit, filter=filter)

def aggregate(self, filter: DataSetFilter | dict | None = None) -> list[DataSetAggregate]:
def aggregate(self, filter: DataSetFilter | dict | None = None) -> builtins.list[DataSetAggregate]:
"""`Aggregate data sets <https://developer.cognite.com/api#tag/Data-sets/operation/aggregateDataSets>`_
Args:
filter (DataSetFilter | dict | None): Filter on data set filter with exact match
Returns:
list[DataSetAggregate]: List of data set aggregates
builtins.list[DataSetAggregate]: List of data set aggregates
Examples:
Expand Down
13 changes: 8 additions & 5 deletions cognite/client/_api/events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Iterator, Literal, Sequence, cast, overload
from typing import TYPE_CHECKING, Any, Iterator, Literal, Sequence, cast, overload

from cognite.client._api_client import APIClient
from cognite.client._constants import LIST_LIMIT_DEFAULT
Expand All @@ -17,6 +17,9 @@
from cognite.client.utils._identifier import IdentifierSequence
from cognite.client.utils._validation import process_asset_subtree_ids, process_data_set_ids

if TYPE_CHECKING:
import builtins


class EventsAPI(APIClient):
_RESOURCE_PATH = "/events"
Expand Down Expand Up @@ -277,14 +280,14 @@ def list(
sort=sort,
)

def aggregate(self, filter: EventFilter | dict | None = None) -> list[AggregateResult]:
def aggregate(self, filter: EventFilter | dict | None = None) -> builtins.list[AggregateResult]:
"""`Aggregate events <https://developer.cognite.com/api#tag/Events/operation/aggregateEvents>`_
Args:
filter (EventFilter | dict | None): Filter on events filter with exact match
Returns:
list[AggregateResult]: List of event aggregates
builtins.list[AggregateResult]: List of event aggregates
Examples:
Expand All @@ -299,15 +302,15 @@ def aggregate(self, filter: EventFilter | dict | None = None) -> list[AggregateR

def aggregate_unique_values(
self, filter: EventFilter | dict | None = None, fields: Sequence[str] | None = None
) -> list[AggregateUniqueValuesResult]:
) -> builtins.list[AggregateUniqueValuesResult]:
"""`Aggregate unique values for events <https://developer.cognite.com/api#tag/Events/operation/aggregateEvents>`_
Args:
filter (EventFilter | dict | None): Filter on events filter with exact match
fields (Sequence[str] | None): The field name(s) to apply the aggregation on. Currently limited to one field.
Returns:
list[AggregateUniqueValuesResult]: List of event aggregates
builtins.list[AggregateUniqueValuesResult]: List of event aggregates
Examples:
Expand Down
6 changes: 4 additions & 2 deletions cognite/client/_api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
from cognite.client.utils._validation import process_asset_subtree_ids, process_data_set_ids

if TYPE_CHECKING:
import builtins

from requests import Response


Expand Down Expand Up @@ -350,14 +352,14 @@ def list(
list_cls=FileMetadataList, resource_cls=FileMetadata, method="POST", limit=limit, filter=filter
)

def aggregate(self, filter: FileMetadataFilter | dict | None = None) -> list[FileAggregate]:
def aggregate(self, filter: FileMetadataFilter | dict | None = None) -> builtins.list[FileAggregate]:
"""`Aggregate files <https://developer.cognite.com/api#tag/Files/operation/aggregateFiles>`_
Args:
filter (FileMetadataFilter | dict | None): Filter on file metadata filter with exact match
Returns:
list[FileAggregate]: List of file aggregates
builtins.list[FileAggregate]: List of file aggregates
Examples:
Expand Down
8 changes: 5 additions & 3 deletions cognite/client/_api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from cognite.client.utils._identifier import Identifier

if TYPE_CHECKING:
import builtins

import pandas

from cognite.client import CogniteClient
Expand Down Expand Up @@ -567,7 +569,7 @@ def list(
raise summary.exceptions[0]
return RowList(summary.joined_results())

def _make_columns_param(self, columns: list[str] | None) -> str | None:
def _make_columns_param(self, columns: builtins.list[str] | None) -> str | None:
if columns is None:
return None
if not isinstance(columns, List):
Expand All @@ -583,7 +585,7 @@ def retrieve_dataframe(
table_name: str,
min_last_updated_time: int | None = None,
max_last_updated_time: int | None = None,
columns: list[str] | None = None,
columns: builtins.list[str] | None = None,
limit: int = LIST_LIMIT_DEFAULT,
) -> pandas.DataFrame:
"""`Retrieve rows in a table as a pandas dataframe. <https://developer.cognite.com/api#tag/Raw/operation/getRows>`_
Expand All @@ -595,7 +597,7 @@ def retrieve_dataframe(
table_name (str): Name of the table.
min_last_updated_time (int | None): Rows must have been last updated after this time. ms since epoch.
max_last_updated_time (int | None): Rows must have been last updated before this time. ms since epoch.
columns (list[str] | None): List of column keys. Set to `None` for retrieving all, use [] to retrieve only row keys.
columns (builtins.list[str] | None): List of column keys. Set to `None` for retrieving all, use [] to retrieve only row keys.
limit (int): The number of rows to retrieve. Defaults to 25. Set to -1, float("inf") or None to return all items.
Returns:
Expand Down
6 changes: 4 additions & 2 deletions cognite/client/_api/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from cognite.client.utils._validation import process_asset_subtree_ids, process_data_set_ids

if TYPE_CHECKING:
import builtins

import pandas

from cognite.client import CogniteClient
Expand Down Expand Up @@ -237,14 +239,14 @@ def list(
).dump(camel_case=True)
return self._list(list_cls=SequenceList, resource_cls=Sequence, method="POST", filter=filter, limit=limit)

def aggregate(self, filter: SequenceFilter | dict | None = None) -> list[SequenceAggregate]:
def aggregate(self, filter: SequenceFilter | dict | None = None) -> builtins.list[SequenceAggregate]:
"""`Aggregate sequences <https://developer.cognite.com/api#tag/Sequences/operation/aggregateSequences>`_
Args:
filter (SequenceFilter | dict | None): Filter on sequence filter with exact match
Returns:
list[SequenceAggregate]: List of sequence aggregates
builtins.list[SequenceAggregate]: List of sequence aggregates
Examples:
Expand Down
6 changes: 4 additions & 2 deletions cognite/client/_api/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from cognite.client.utils._validation import process_asset_subtree_ids, process_data_set_ids

if TYPE_CHECKING:
import builtins

from cognite.client import CogniteClient
from cognite.client.config import ClientConfig

Expand Down Expand Up @@ -269,14 +271,14 @@ def list(
partitions=partitions,
)

def aggregate(self, filter: TimeSeriesFilter | dict | None = None) -> list[TimeSeriesAggregate]:
def aggregate(self, filter: TimeSeriesFilter | dict | None = None) -> builtins.list[TimeSeriesAggregate]:
"""`Aggregate time series <https://developer.cognite.com/api#tag/Time-series/operation/aggregateTimeSeries>`_
Args:
filter (TimeSeriesFilter | dict | None): Filter on time series filter with exact match
Returns:
list[TimeSeriesAggregate]: List of sequence aggregates
builtins.list[TimeSeriesAggregate]: List of sequence aggregates
Examples:
Expand Down

0 comments on commit ec38b45

Please sign in to comment.