Skip to content

Commit 9fedfa6

Browse files
committed
Fix mypy violations
1 parent 2b4db14 commit 9fedfa6

15 files changed

+215
-229
lines changed

pyatlan/cache/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
from pyatlan.cache.role_cache import RoleCache
2-
from pyatlan.cache.classification_cache import ClassificationCache
3-
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache

pyatlan/cache/classification_cache.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from typing import Optional
12

23
from pyatlan.client.atlan import AtlanClient
34
from pyatlan.client.typedef import TypeDefClient
4-
from pyatlan.model.typedef import ClassificationDef
55
from pyatlan.model.enums import AtlanTypeCategory
6+
from pyatlan.model.typedef import ClassificationDef
67

7-
from typing import Optional
88

99
class ClassificationCache:
1010

@@ -16,7 +16,9 @@ class ClassificationCache:
1616

1717
@classmethod
1818
def _refresh_cache(cls) -> None:
19-
response = TypeDefClient(AtlanClient()).get_typedefs(type=AtlanTypeCategory.CLASSIFICATION)
19+
response = TypeDefClient(AtlanClient()).get_typedefs(
20+
type=AtlanTypeCategory.CLASSIFICATION
21+
)
2022
if response is not None:
2123
cls.cache_by_id = dict()
2224
cls.map_id_to_name = dict()
@@ -34,7 +36,7 @@ def get_id_for_name(cls, name: str) -> Optional[str]:
3436
Translate the provided human-readable classification name to its Atlan-internal ID string.
3537
"""
3638
cls_id = cls.map_name_to_id.get(name)
37-
if not cls_id and not name in cls.deleted_names:
39+
if not cls_id and name not in cls.deleted_names:
3840
# If not found, refresh the cache and look again (could be stale)
3941
cls._refresh_cache()
4042
cls_id = cls.map_name_to_id.get(name)
@@ -51,7 +53,7 @@ def get_name_for_id(cls, idstr: str) -> Optional[str]:
5153
Translate the provided Atlan-internal classification ID string to the human-readable classification name.
5254
"""
5355
cls_name = cls.map_id_to_name.get(idstr)
54-
if not cls_name and not idstr in cls.deleted_ids:
56+
if not cls_name and idstr not in cls.deleted_ids:
5557
# If not found, refresh the cache and look again (could be stale)
5658
cls._refresh_cache()
5759
cls_name = cls.map_id_to_name.get(idstr)

pyatlan/cache/custom_metadata_cache.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
from typing import Optional
12

23
from pyatlan.client.atlan import AtlanClient
34
from pyatlan.client.typedef import TypeDefClient
4-
from pyatlan.model.typedef import CustomMetadataDef, AttributeDef
5+
from pyatlan.error import LogicError, NotFoundError
56
from pyatlan.model.enums import AtlanTypeCategory
6-
from pyatlan.error import LogicError
7+
from pyatlan.model.typedef import AttributeDef, CustomMetadataDef
78

8-
from typing import Optional
99

1010
class CustomMetadataCache:
1111

@@ -18,7 +18,9 @@ class CustomMetadataCache:
1818

1919
@classmethod
2020
def _refresh_cache(cls) -> None:
21-
response = TypeDefClient(AtlanClient()).get_typedefs(type=AtlanTypeCategory.CUSTOM_METADATA)
21+
response = TypeDefClient(AtlanClient()).get_typedefs(
22+
type=AtlanTypeCategory.CUSTOM_METADATA
23+
)
2224
if response is not None:
2325
cls.cache_by_id = dict()
2426
cls.map_id_to_name = dict()
@@ -44,12 +46,14 @@ def _refresh_cache(cls) -> None:
4446
else:
4547
if attr_name in cls.map_attr_name_to_id[type_id]:
4648
raise LogicError(
47-
"Multiple custom attributes with exactly the same name (" + attr_name + ") found for: " + type_name,
48-
code="ATLAN-PYTHON-500-100"
49+
"Multiple custom attributes with exactly the same name ("
50+
+ attr_name
51+
+ ") found for: "
52+
+ type_name,
53+
code="ATLAN-PYTHON-500-100",
4954
)
5055
cls.map_attr_name_to_id[type_id][attr_name] = attr_id
5156

52-
5357
@classmethod
5458
def get_id_for_name(cls, name: str) -> Optional[str]:
5559
"""
@@ -77,7 +81,9 @@ def get_name_for_id(cls, idstr: str) -> Optional[str]:
7781
return cls.map_id_to_name.get(idstr)
7882

7983
@classmethod
80-
def get_all_custom_attributes(cls, include_deleted: bool=False, force_refresh: bool=False) -> dict[str, list[AttributeDef]]:
84+
def get_all_custom_attributes(
85+
cls, include_deleted: bool = False, force_refresh: bool = False
86+
) -> dict[str, list[AttributeDef]]:
8187
"""
8288
Retrieve all the custom metadata attributes. The map will be keyed by custom metadata set
8389
name, and the value will be a listing of all the attributes within that set (with all the details
@@ -88,6 +94,10 @@ def get_all_custom_attributes(cls, include_deleted: bool=False, force_refresh: b
8894
m = {}
8995
for type_id, cm in cls.cache_by_id.items():
9096
type_name = cls.get_name_for_id(type_id)
97+
if not type_name:
98+
raise NotFoundError(
99+
f"The type_name for {type_id} could not be found.", code="fixme"
100+
)
91101
attribute_defs = cm.attribute_defs
92102
if include_deleted:
93103
to_include = attribute_defs

pyatlan/cache/role_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
from typing import Optional
12

23
from pyatlan.client.atlan import AtlanClient
34
from pyatlan.client.role import RoleClient
45
from pyatlan.model.role import AtlanRole
56

6-
from typing import Optional
77

88
class RoleCache:
99

pyatlan/client/atlan.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import logging
2323
import os
2424

25-
2625
import requests
26+
from pydantic import BaseSettings, Field, HttpUrl, PrivateAttr
2727

28-
from pydantic import BaseSettings, HttpUrl, PrivateAttr, Field
2928
from pyatlan.exceptions import AtlanServiceException
30-
from pyatlan.utils import HTTPMethod, HTTPStatus, get_logger
3129
from pyatlan.model.core import AtlanObject
30+
from pyatlan.utils import HTTPMethod, HTTPStatus, get_logger
3231

3332
LOGGER = get_logger()
3433

@@ -85,7 +84,10 @@ def call_api(self, api, query_params=None, request_obj=None):
8584
return None
8685
elif response.status_code == api.expected_status:
8786
try:
88-
if response.content is None or response.status_code == HTTPStatus.NO_CONTENT:
87+
if (
88+
response.content is None
89+
or response.status_code == HTTPStatus.NO_CONTENT
90+
):
8991
return None
9092
if LOGGER.isEnabledFor(logging.DEBUG):
9193
LOGGER.debug(

pyatlan/client/role.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@
1717
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
20-
from pyatlan.client.atlan import AtlanClient
2120
from typing import Optional
22-
from pyatlan.model.role import (
23-
RoleResponse
24-
)
25-
from pyatlan.utils import (
26-
API,
27-
ADMIN_URI,
28-
HTTPMethod,
29-
HTTPStatus,
30-
)
21+
22+
from pyatlan.client.atlan import AtlanClient
23+
from pyatlan.model.role import RoleResponse
24+
from pyatlan.utils import ADMIN_URI, API, HTTPMethod, HTTPStatus
3125

3226

3327
class RoleClient:
3428
ROLE_API = ADMIN_URI + "roles"
35-
29+
3630
# Role APIs
3731
GET_ROLES = API(ROLE_API, HTTPMethod.GET, HTTPStatus.OK)
3832

3933
def __init__(self, client: AtlanClient):
4034
self.client = client
4135

42-
43-
def get_roles(self, limit: int, filter: Optional[str]=None, sort: Optional[str]=None, count: bool=True, offset: int=0) -> RoleResponse:
36+
def get_roles(
37+
self,
38+
limit: int,
39+
filter: Optional[str] = None,
40+
sort: Optional[str] = None,
41+
count: bool = True,
42+
offset: int = 0,
43+
) -> RoleResponse:
4444
if filter is None:
4545
filter = ""
4646
if sort is None:
@@ -50,13 +50,14 @@ def get_roles(self, limit: int, filter: Optional[str]=None, sort: Optional[str]=
5050
"sort": sort,
5151
"count": count,
5252
"offset": offset,
53-
"limit": limit
53+
"limit": limit,
5454
}
55-
raw_json = self.client.call_api(RoleClient.GET_ROLES.format_path_with_params(), query_params)
55+
raw_json = self.client.call_api(
56+
RoleClient.GET_ROLES.format_path_with_params(), query_params
57+
)
5658
response = RoleResponse(**raw_json)
5759
return response
5860

59-
6061
def get_all_roles(self) -> RoleResponse:
6162
"""
6263
Retrieve all roles defined in Atlan.

pyatlan/client/typedef.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
from pyatlan.model.typedef import TypeDefResponse
22-
from pyatlan.utils import API, BASE_URI, HTTPMethod, HTTPStatus
2321
from pyatlan.client.atlan import AtlanClient
24-
from pyatlan.model.enums import AtlanTypeCategory
25-
from pyatlan.model.typedef import TypeDef, ClassificationDef, CustomMetadataDef
2622
from pyatlan.exceptions import InvalidRequestException
23+
from pyatlan.model.enums import AtlanTypeCategory
24+
from pyatlan.model.typedef import (
25+
ClassificationDef,
26+
CustomMetadataDef,
27+
TypeDef,
28+
TypeDefResponse,
29+
)
30+
from pyatlan.utils import API, BASE_URI, HTTPMethod, HTTPStatus
2731

2832

2933
class TypeDefClient:
@@ -55,9 +59,7 @@ def get_all_typedefs(self) -> TypeDefResponse:
5559
return TypeDefResponse(**raw_json)
5660

5761
def get_typedefs(self, type: AtlanTypeCategory) -> TypeDefResponse:
58-
query_params = {
59-
"type": type.value
60-
}
62+
query_params = {"type": type.value}
6163
raw_json = self.client.call_api(
6264
TypeDefClient.GET_ALL_TYPE_DEFS.format_path_with_params(),
6365
query_params,
@@ -74,7 +76,7 @@ def create_typedef(self, typedef: TypeDef) -> TypeDefResponse:
7476
struct_defs=[],
7577
entity_defs=[],
7678
relationship_defs=[],
77-
businessMetadataDefs=[]
79+
businessMetadataDefs=[],
7880
)
7981
elif isinstance(typedef, CustomMetadataDef):
8082
# Set up the request payload...
@@ -84,22 +86,25 @@ def create_typedef(self, typedef: TypeDef) -> TypeDefResponse:
8486
struct_defs=[],
8587
entity_defs=[],
8688
relationship_defs=[],
87-
businessMetadataDefs=[typedef]
89+
businessMetadataDefs=[typedef],
8890
)
8991
else:
9092
raise InvalidRequestException(
91-
"Unable to create new type definitions of category: " + typedef.category.value,
92-
param="category"
93+
"Unable to create new type definitions of category: "
94+
+ typedef.category.value,
95+
param="category",
9396
)
9497
# Throw an invalid request exception
9598
raw_json = self.client.call_api(
96-
TypeDefClient.CREATE_TYPE_DEFS,
97-
request_obj=payload
99+
TypeDefClient.CREATE_TYPE_DEFS, request_obj=payload
98100
)
99101
return TypeDefResponse(**raw_json)
100102

101103
def purge_typedef(self, internal_name: str) -> None:
102-
self.client.call_api(TypeDefClient.DELETE_TYPE_DEF_BY_NAME.format_path_with_params(internal_name))
104+
self.client.call_api(
105+
TypeDefClient.DELETE_TYPE_DEF_BY_NAME.format_path_with_params(internal_name)
106+
)
107+
103108

104109
if __name__ == "__main__":
105110
client = TypeDefClient(AtlanClient())

0 commit comments

Comments
 (0)