Skip to content

Commit

Permalink
refactor: replace type with Type
Browse files Browse the repository at this point in the history
mypy says that in some cases, it is impossible to use type for typing because there is already an attribute named string, which is, for example, type str. Changed these occurrences back to Type and annotating them with # noqa: UP006.

JIRA: PSDK-203
risk: low
  • Loading branch information
hkad98 committed Aug 14, 2024
1 parent 86c75ba commit 4b53b46
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions gooddata-sdk/gooddata_sdk/catalog/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Any, Optional, TypeVar
from typing import Any, Optional, Type, TypeVar

import attr
from cattrs import structure
Expand Down Expand Up @@ -99,7 +99,7 @@ def from_api(
return structure(entity, cls)

@classmethod
def from_dict(cls: type[U], data: dict[str, Any]) -> U:
def from_dict(cls: Type[U], data: dict[str, Any]) -> U: # noqa: UP006
return NotImplemented

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Any, Optional, Union
from typing import Any, Optional, Type, Union
from warnings import warn

import attr
Expand Down Expand Up @@ -124,7 +124,7 @@ def to_test_request(
return TestDefinitionRequest(type=self.type, url=self.url, **kwargs)

@staticmethod
def client_class() -> type[DeclarativeDataSource]:
def client_class() -> Type[DeclarativeDataSource]: # noqa: UP006
return DeclarativeDataSource

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Optional
from typing import Optional, Type

import attr
from gooddata_api_client.model.declarative_table import DeclarativeTable
Expand All @@ -21,7 +21,7 @@ class CatalogDeclarativeTable(Base):
name_prefix: Optional[str] = None

@staticmethod
def client_class() -> type[DeclarativeTable]:
def client_class() -> Type[DeclarativeTable]: # noqa: UP006
return DeclarativeTable

def store_to_disk(self, pdm_folder: Path) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Any, ClassVar, Optional, TypeVar
from typing import Any, ClassVar, Optional, Type, TypeVar

import attr
from cattrs import structure
Expand Down Expand Up @@ -77,7 +77,7 @@ def to_api(self) -> Any:
)

@classmethod
def from_api(cls: type[U], entity: dict[str, Any]) -> U:
def from_api(cls: Type[U], entity: dict[str, Any]) -> U: # noqa: UP006
attributes = entity["attributes"]
credentials = Credentials.create(cls._SUPPORTED_CREDENTIALS, entity)
return structure({"id": entity["id"], "credentials": credentials, **attributes}, cls)
Expand Down
4 changes: 2 additions & 2 deletions gooddata-sdk/gooddata_sdk/catalog/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import base64
import os
from pathlib import Path
from typing import Any, ClassVar, Optional, TypeVar, Union
from typing import Any, ClassVar, Optional, Type, TypeVar, Union

import attr

Expand Down Expand Up @@ -62,7 +62,7 @@ def obj_id(self) -> ObjId:

@classmethod
def from_api(
cls: type[T],
cls: Type[T], # noqa: UP006
entity: dict[str, Any],
side_loads: Optional[list[Any]] = None,
related_entities: Optional[AllPagedEntities] = None,
Expand Down
18 changes: 10 additions & 8 deletions gooddata-sdk/gooddata_sdk/catalog/identifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Type

import attr
from gooddata_api_client.model.assignee_identifier import AssigneeIdentifier
from gooddata_api_client.model.dataset_workspace_data_filter_identifier import DatasetWorkspaceDataFilterIdentifier
Expand All @@ -19,7 +21,7 @@ class CatalogWorkspaceIdentifier(Base):
id: str

@staticmethod
def client_class() -> type[WorkspaceIdentifier]:
def client_class() -> Type[WorkspaceIdentifier]: # noqa: UP006
return WorkspaceIdentifier


Expand All @@ -28,7 +30,7 @@ class CatalogReferenceIdentifier(Base):
id: str

@staticmethod
def client_class() -> type[ReferenceIdentifier]:
def client_class() -> Type[ReferenceIdentifier]: # noqa: UP006
return ReferenceIdentifier


Expand All @@ -38,7 +40,7 @@ class CatalogGrainIdentifier(Base):
type: str = attr.field(validator=value_in_allowed)

@staticmethod
def client_class() -> type[GrainIdentifier]:
def client_class() -> Type[GrainIdentifier]: # noqa: UP006
return GrainIdentifier


Expand All @@ -48,7 +50,7 @@ class CatalogAssigneeIdentifier(Base):
type: str = attr.field(validator=value_in_allowed)

@staticmethod
def client_class() -> type[AssigneeIdentifier]:
def client_class() -> Type[AssigneeIdentifier]: # noqa: UP006
return AssigneeIdentifier


Expand All @@ -58,7 +60,7 @@ class CatalogDeclarativeUserGroupIdentifier(Base):
type: str = attr.field(validator=value_in_allowed)

@staticmethod
def client_class() -> type[DeclarativeUserGroupIdentifier]:
def client_class() -> Type[DeclarativeUserGroupIdentifier]: # noqa: UP006
return DeclarativeUserGroupIdentifier


Expand All @@ -68,7 +70,7 @@ class CatalogUserIdentifier(Base):
type: str = attr.field(validator=value_in_allowed)

@staticmethod
def client_class() -> type[DeclarativeUserIdentifier]:
def client_class() -> Type[DeclarativeUserIdentifier]: # noqa: UP006
return DeclarativeUserIdentifier


Expand All @@ -78,7 +80,7 @@ class CatalogLabelIdentifier(Base):
type: str = attr.field(validator=value_in_allowed)

@staticmethod
def client_class() -> type[LabelIdentifier]:
def client_class() -> Type[LabelIdentifier]: # noqa: UP006
return LabelIdentifier


Expand All @@ -87,5 +89,5 @@ class CatalogDatasetWorkspaceDataFilterIdentifier(Base):
id: str

@staticmethod
def client_class() -> type[DatasetWorkspaceDataFilterIdentifier]:
def client_class() -> Type[DatasetWorkspaceDataFilterIdentifier]: # noqa: UP006
return DatasetWorkspaceDataFilterIdentifier
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2023 GoodData Corporation
from __future__ import annotations

from typing import Any, Optional
from typing import Any, Optional, Type

import attr
from gooddata_api_client.model.json_api_organization_setting_in import JsonApiOrganizationSettingIn
Expand Down Expand Up @@ -30,5 +30,5 @@ class CatalogOrganizationSettingAttributes(Base):
content: dict[str, Any]

@staticmethod
def client_class() -> type[JsonApiOrganizationSettingInAttributes]:
def client_class() -> Type[JsonApiOrganizationSettingInAttributes]: # noqa: UP006
return JsonApiOrganizationSettingInAttributes
4 changes: 3 additions & 1 deletion gooddata-sdk/gooddata_sdk/catalog/rule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Type

import attr
from gooddata_api_client.model.assignee_rule import AssigneeRule

Expand All @@ -12,5 +14,5 @@ class CatalogAssigneeRule(Base):
type: str = attr.field(validator=value_in_allowed)

@staticmethod
def client_class() -> type[AssigneeRule]:
def client_class() -> Type[AssigneeRule]: # noqa: UP006
return AssigneeRule
4 changes: 2 additions & 2 deletions gooddata-sdk/gooddata_sdk/catalog/setting.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Any, Optional
from typing import Any, Optional, Type

import attr
from gooddata_api_client.model.declarative_custom_application_setting import DeclarativeCustomApplicationSetting
Expand All @@ -17,7 +17,7 @@ class CatalogDeclarativeSetting(Base):
content: Optional[dict[str, Any]] = None

@staticmethod
def client_class() -> type[DeclarativeSetting]:
def client_class() -> Type[DeclarativeSetting]: # noqa: UP006
return DeclarativeSetting


Expand Down
4 changes: 3 additions & 1 deletion gooddata-sdk/gooddata_sdk/catalog/validate_by_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) 2023 GoodData Corporation
from __future__ import annotations

from typing import Type

import attr
from gooddata_api_client.model.validate_by_item import ValidateByItem

Expand All @@ -13,5 +15,5 @@ class CatalogValidateByItem(Base):
type: str

@staticmethod
def client_class() -> type[ValidateByItem]:
def client_class() -> Type[ValidateByItem]: # noqa: UP006
return ValidateByItem
10 changes: 6 additions & 4 deletions gooddata-sdk/gooddata_sdk/catalog/workspace/content_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def get_attributes_catalog(self, workspace_id: str) -> list[CatalogAttribute]:
_check_return_type=False,
)
attributes = load_all_entities(get_attributes)
catalog_attributes = [CatalogAttribute.from_api(a, side_loads=attributes.included) for a in attributes.data]
catalog_attributes: list[CatalogAttribute] = [
CatalogAttribute.from_api(a, side_loads=attributes.included) for a in attributes.data
]
return catalog_attributes

def get_labels_catalog(self, workspace_id: str) -> list[CatalogLabel]:
Expand All @@ -141,7 +143,7 @@ def get_labels_catalog(self, workspace_id: str) -> list[CatalogLabel]:
_check_return_type=False,
)
labels = load_all_entities(get_labels)
catalog_labels = [CatalogLabel.from_api(label) for label in labels.data]
catalog_labels: list[CatalogLabel] = [CatalogLabel.from_api(label) for label in labels.data]
return catalog_labels

def get_metrics_catalog(self, workspace_id: str) -> list[CatalogMetric]:
Expand All @@ -159,7 +161,7 @@ def get_metrics_catalog(self, workspace_id: str) -> list[CatalogMetric]:
self._entities_api.get_all_entities_metrics, workspace_id, _check_return_type=False
)
metrics = load_all_entities(get_metrics)
catalog_metrics = [CatalogMetric.from_api(metric) for metric in metrics.data]
catalog_metrics: list[CatalogMetric] = [CatalogMetric.from_api(metric) for metric in metrics.data]
return catalog_metrics

def get_facts_catalog(self, workspace_id: str) -> list[CatalogFact]:
Expand All @@ -175,7 +177,7 @@ def get_facts_catalog(self, workspace_id: str) -> list[CatalogFact]:
"""
get_facts = functools.partial(self._entities_api.get_all_entities_facts, workspace_id, _check_return_type=False)
facts = load_all_entities(get_facts)
catalog_facts = [CatalogFact.from_api(fact) for fact in facts.data]
catalog_facts: list[CatalogFact] = [CatalogFact.from_api(fact) for fact in facts.data]
return catalog_facts

def get_dependent_entities_graph(self, workspace_id: str) -> CatalogDependentEntitiesResponse:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import Optional
from typing import Optional, Type

import attr
from gooddata_api_client.model.dependent_entities_graph import DependentEntitiesGraph
Expand All @@ -18,7 +18,7 @@ class CatalogDependentEntitiesRequest(Base):
identifiers: list[CatalogEntityIdentifier] = attr.field(factory=list)

@staticmethod
def client_class() -> type[DependentEntitiesRequest]:
def client_class() -> Type[DependentEntitiesRequest]: # noqa: UP006
return DependentEntitiesRequest


Expand All @@ -27,7 +27,7 @@ class CatalogDependentEntitiesResponse(Base):
graph: CatalogDependentEntitiesGraph

@staticmethod
def client_class() -> type[DependentEntitiesResponse]:
def client_class() -> Type[DependentEntitiesResponse]: # noqa: UP006
return DependentEntitiesResponse


Expand All @@ -37,7 +37,7 @@ class CatalogDependentEntitiesGraph(Base):
edges: list[list[CatalogEntityIdentifier]] = attr.field(factory=list)

@staticmethod
def client_class() -> type[DependentEntitiesGraph]:
def client_class() -> Type[DependentEntitiesGraph]: # noqa: UP006
return DependentEntitiesGraph


Expand All @@ -48,7 +48,7 @@ class CatalogDependentEntitiesNode(Base):
title: Optional[str] = None

@staticmethod
def client_class() -> type[DependentEntitiesNode]:
def client_class() -> Type[DependentEntitiesNode]: # noqa: UP006
return DependentEntitiesNode


Expand All @@ -58,5 +58,5 @@ class CatalogEntityIdentifier(Base):
type: str

@staticmethod
def client_class() -> type[EntityIdentifier]:
def client_class() -> Type[EntityIdentifier]: # noqa: UP006
return EntityIdentifier
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ def create_workspace_content_catalog(
attributes: AllPagedEntities,
metrics: AllPagedEntities,
) -> CatalogWorkspaceContent:
catalog_datasets = [
catalog_datasets: list[CatalogDataset] = [
CatalogDataset.from_api(d, side_loads=datasets.included, related_entities=attributes) for d in datasets.data
]

catalog_metrics = [CatalogMetric.from_api(metric) for metric in metrics.data]
catalog_metrics: list[CatalogMetric] = [CatalogMetric.from_api(metric) for metric in metrics.data]

return cls(
valid_obj_fun=valid_obj_fun,
Expand Down

0 comments on commit 4b53b46

Please sign in to comment.