Skip to content

Commit

Permalink
50 or so new mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Apr 27, 2023
1 parent db2eb44 commit 4bdaba2
Show file tree
Hide file tree
Showing 30 changed files with 132 additions and 98 deletions.
2 changes: 1 addition & 1 deletion cognite/client/_api/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def list(
external_id_prefix: str = None,
aggregated_properties: Sequence[str] = None,
partitions: int = None,
limit: int = LIST_LIMIT_DEFAULT,
limit: Optional[int] = LIST_LIMIT_DEFAULT,
) -> AssetList:
"""`List assets <https://docs.cognite.com/api/v1/#operation/listAssets>`_
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/_api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def list(

def retrieve(
self, call_id: int, function_id: Optional[int] = None, function_external_id: Optional[str] = None
) -> Union[FunctionCallList, FunctionCall, None]:
) -> Optional[FunctionCall]:
"""`Retrieve a single function call by id. <https://docs.cognite.com/api/v1/#operation/byIdsFunctionCalls>`_
Args:
Expand All @@ -740,7 +740,7 @@ def retrieve(
function_external_id (str, optional): External ID of the function on which the call was made.
Returns:
Union[FunctionCallList, FunctionCall, None]: Requested function call.
Optional[FunctionCall]: Requested function call or None if not found.
Examples:
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/_api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def delete(self, db_name: str, name: Union[str, Sequence[str]]) -> None:
task_unwrap_fn=lambda task: task["json"]["items"], task_list_element_unwrap_fn=lambda el: el["name"]
)

def list(self, db_name: str, limit: int = LIST_LIMIT_DEFAULT) -> TableList:
def list(self, db_name: str, limit: Optional[int] = LIST_LIMIT_DEFAULT) -> TableList:
"""`List tables <https://docs.cognite.com/api/v1/#operation/getTables>`_
Args:
Expand Down Expand Up @@ -494,7 +494,7 @@ def list(
min_last_updated_time: int = None,
max_last_updated_time: int = None,
columns: List[str] = None,
limit: int = LIST_LIMIT_DEFAULT,
limit: Optional[int] = LIST_LIMIT_DEFAULT,
) -> RowList:
"""`List rows in a table. <https://docs.cognite.com/api/v1/#operation/getRows>`_
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/_api/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,11 @@ def retrieve(
column_external_ids (Optional[SequenceType[str]]): List of external id for the columns of the sequence. If 'None' is passed, all columns will be retrieved.
id (int): Id of sequence.
external_id (str): External id of sequence.
limit (int): Maximum number of rows to return per sequence. 10000 is the maximum limit per request.
limit (int): Maximum number of rows to return per sequence.
Returns:
List of sequence data
Union[SequenceData, SequenceDataList]: SequenceData if single identifier was given, else SequenceDataList
Examples:
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, config: ClientConfig, api_version: Optional[str], cognite_cli
self._config = config
self._api_version = api_version
self._api_subversion = config.api_subversion
self._cognite_client = cognite_client
self._cognite_client = cognite_client # type: ignore [assignment]
self._init_http_clients()

self._CREATE_LIMIT = 1000
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/data_classes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class CogniteResourceList(Generic[T_CogniteResource], CogniteBaseList, _WithClie

def __init__(self, items: List[T_CogniteResource], cognite_client: Optional[CogniteClient] = None):
super().__init__(items)
self._cognite_client = cognite_client
self._cognite_client = cognite_client # type: ignore [assignment]

@classmethod
def _load( # type: ignore [override]
Expand Down
12 changes: 10 additions & 2 deletions cognite/client/data_classes/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(
self.last_updated_time = last_updated_time
self.root_id = root_id
self.aggregates = aggregates
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

@classmethod
def _load(cls, resource: Dict, cognite_client: CogniteClient = None) -> Asset:
Expand All @@ -158,14 +158,18 @@ def parent(self) -> Asset:
"""
if self.parent_id is None:
raise ValueError("parent_id is None")
return self._cognite_client.assets.retrieve(id=self.parent_id)
return self._cognite_client.assets.retrieve_multiple(
ids=[self.parent_id],
ignore_unknown_ids=False,
)[0]

def children(self) -> AssetList:
"""Returns the children of this asset.
Returns:
AssetList: The requested assets
"""
assert self.id is not None
return self._cognite_client.assets.list(parent_ids=[self.id], limit=None)

def subtree(self, depth: int = None) -> AssetList:
Expand All @@ -185,6 +189,7 @@ def time_series(self, **kwargs: Any) -> TimeSeriesList:
Returns:
TimeSeriesList: All time series related to this asset.
"""
assert self.id is not None
return self._cognite_client.time_series.list(asset_ids=[self.id], **kwargs)

def sequences(self, **kwargs: Any) -> SequenceList:
Expand All @@ -193,6 +198,7 @@ def sequences(self, **kwargs: Any) -> SequenceList:
Returns:
SequenceList: All sequences related to this asset.
"""
assert self.id is not None
return self._cognite_client.sequences.list(asset_ids=[self.id], **kwargs)

def events(self, **kwargs: Any) -> EventList:
Expand All @@ -202,6 +208,7 @@ def events(self, **kwargs: Any) -> EventList:
EventList: All events related to this asset.
"""

assert self.id is not None
return self._cognite_client.events.list(asset_ids=[self.id], **kwargs)

def files(self, **kwargs: Any) -> FileMetadataList:
Expand All @@ -210,6 +217,7 @@ def files(self, **kwargs: Any) -> FileMetadataList:
Returns:
FileMetadataList: Metadata about all files related to this asset.
"""
assert self.id is not None
return self._cognite_client.files.list(asset_ids=[self.id], **kwargs)

def dump(self, camel_case: bool = False) -> Dict[str, Any]:
Expand Down
14 changes: 7 additions & 7 deletions cognite/client/data_classes/contextualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(
self.job_token = job_token
self._result: Optional[Dict[str, Any]] = None
self._status_path = status_path
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def update_status(self) -> str:
"""Updates the model status and returns it"""
Expand Down Expand Up @@ -207,7 +207,7 @@ def __init__(
self.name = name
self.description = description
self.external_id = external_id
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def __str__(self) -> str:
return f"{self.__class__.__name__}(id={self.id}, status={self.status}, error={self.error_message})"
Expand Down Expand Up @@ -369,7 +369,7 @@ def __init__(
self.page = page
self.png_url = png_url
self.svg_url = svg_url
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]


class DiagramConvertPageList(CogniteResourceList):
Expand All @@ -387,7 +387,7 @@ def __init__(
self.file_id = file_id
self.file_external_id = file_external_id
self.results = results
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def __len__(self) -> int:
assert self.results
Expand Down Expand Up @@ -461,7 +461,7 @@ def __init__(
self.annotations = annotations
self.error_message = error_message
self.page_range = page_range
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def to_pandas(self, camel_case: bool = False) -> pandas.DataFrame: # type: ignore[override]
"""Convert the instance into a pandas DataFrame.
Expand Down Expand Up @@ -607,7 +607,7 @@ def __init__(self, job_ids: List[int], cognite_client: CogniteClient = None):
"Breaking changes can happen in between patch versions."
)

self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client: CogniteClient = cognite_client # type: ignore [assignment]
if not job_ids:
raise ValueError("You need to specify job_ids")
self.job_ids = job_ids
Expand Down Expand Up @@ -720,7 +720,7 @@ def __init__(
self.predictions = self._process_predictions_dict(predictions) if isinstance(predictions, Dict) else predictions

self._predictions_dict = predictions # The "raw" predictions dict returned by the endpoint
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

@classmethod
def _load(cls, resource: Dict, cognite_client: CogniteClient = None) -> VisionExtractItem:
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/data_classes/data_sets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Union, cast
from typing import TYPE_CHECKING, Any, Dict, List, Union

from cognite.client.data_classes._base import (
CogniteFilter,
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(
self.id = id
self.created_time = created_time
self.last_updated_time = last_updated_time
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]


class DataSetFilter(CogniteFilter):
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/data_classes/events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Union, cast
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Union

from cognite.client.data_classes._base import (
CogniteFilter,
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(
self.id = id
self.last_updated_time = last_updated_time
self.created_time = created_time
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]


class EventFilter(CogniteFilter):
Expand Down
8 changes: 4 additions & 4 deletions cognite/client/data_classes/extractionpipelines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Union, cast
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Union

from cognite.client.data_classes._base import (
CogniteFilter,
Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(
self.created_time = created_time
self.last_updated_time = last_updated_time
self.created_by = created_by
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

@classmethod
def _load(cls, resource: Dict, cognite_client: CogniteClient = None) -> ExtractionPipeline:
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(
self.status = status
self.message = message
self.created_time = created_time
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

@classmethod
def _load(cls, resource: Dict, cognite_client: CogniteClient = None) -> ExtractionPipelineRun:
Expand Down Expand Up @@ -309,7 +309,7 @@ def __init__(
self.revision = revision
self.description = description
self.created_time = created_time
self._cognite_client = cognite_client
self._cognite_client = cognite_client # type: ignore [assignment]


class ExtractionPipelineConfig(ExtractionPipelineConfigRevision):
Expand Down
4 changes: 2 additions & 2 deletions cognite/client/data_classes/files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Union, cast
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Union

from cognite.client.data_classes._base import (
CogniteFilter,
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(
self.uploaded_time = uploaded_time
self.created_time = created_time
self.last_updated_time = last_updated_time
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

@classmethod
def _load(cls, resource: Dict, cognite_client: CogniteClient = None) -> FileMetadata:
Expand Down
16 changes: 11 additions & 5 deletions cognite/client/data_classes/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
self.runtime_version = runtime_version
self.metadata = metadata
self.error = error
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def call(self, data: Optional[Dict] = None, wait: bool = True) -> FunctionCall:
"""`Call this particular function. <https://docs.cognite.com/api/v1/#operation/postFunctionsCall>`_
Expand Down Expand Up @@ -143,14 +143,14 @@ def list_schedules(self, limit: Optional[int] = LIST_LIMIT_DEFAULT) -> FunctionS

return (schedules_by_external_id + schedules_by_id)[:limit]

def retrieve_call(self, id: int) -> FunctionCall:
def retrieve_call(self, id: int) -> Optional[FunctionCall]:
"""`Retrieve call by id. <https://docs.cognite.com/api/v1/#operation/getFunctionCall>`_
Args:
id (int): ID of the call.
Returns:
FunctionCall: Function call.
Optional[FunctionCall]: Requested function call or None if not found.
"""
return self._cognite_client.functions.calls.retrieve(call_id=id, function_id=self.id)

Expand Down Expand Up @@ -241,7 +241,7 @@ def __init__(
self.created_time = created_time
self.session_id = session_id
self.when = when
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def get_input_data(self) -> Optional[dict]:
"""
Expand All @@ -251,6 +251,7 @@ def get_input_data(self) -> Optional[dict]:
Optional[Dict]: Input data to the associated function or None if not set. This data is passed
deserialized into the function through the data argument.
"""
assert self.id is not None
return self._cognite_client.functions.schedules.get_input_data(id=self.id)


Expand Down Expand Up @@ -312,14 +313,15 @@ def __init__(
self.schedule_id = schedule_id
self.error = error
self.function_id = function_id
self._cognite_client = cast("CogniteClient", cognite_client)
self._cognite_client = cognite_client # type: ignore [assignment]

def get_response(self) -> Dict:
"""Retrieve the response from this function call.
Returns:
Response from the function call.
"""
assert self.id is not None
return self._cognite_client.functions.calls.get_response(call_id=self.id, function_id=self.function_id)

def get_logs(self) -> FunctionCallLog:
Expand All @@ -328,6 +330,7 @@ def get_logs(self) -> FunctionCallLog:
Returns:
FunctionCallLog: Log for the function call.
"""
assert self.id is not None
return self._cognite_client.functions.calls.get_logs(call_id=self.id, function_id=self.function_id)

def update(self) -> None:
Expand All @@ -336,7 +339,10 @@ def update(self) -> None:
Returns:
None
"""
assert self.id is not None
latest = self._cognite_client.functions.calls.retrieve(call_id=self.id, function_id=self.function_id)
if latest is None:
raise RuntimeError("Unable to update the function call object")
self.status = latest.status
self.end_time = latest.end_time
self.error = latest.error
Expand Down
Loading

0 comments on commit 4bdaba2

Please sign in to comment.