Skip to content

Commit 009fed3

Browse files
MESH-2092 linting fixes
1 parent 1462946 commit 009fed3

8 files changed

Lines changed: 197 additions & 212 deletions

File tree

mesh_client/__init__.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from io import BytesIO
1717
from itertools import chain
1818
from types import TracebackType
19-
from typing import Any, Dict, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, cast
19+
from typing import Any, NoReturn, Optional, TypeVar, Union, cast
2020
from urllib.parse import quote as q
2121
from urllib.parse import urlparse
2222

@@ -46,14 +46,14 @@
4646
TrackingResponse_v2,
4747
)
4848

49-
if sys.version_info[:2] < (3, 8):
50-
warnings.warn("python 3.7 is now end of life", category=DeprecationWarning, stacklevel=2)
49+
if sys.version_info[:2] < (3, 9): # noqa: UP036
50+
warnings.warn(
51+
"python versions < 3.9 are end of life and no longer supported as of mesh-client v4",
52+
category=DeprecationWarning,
53+
stacklevel=2,
54+
)
5155

52-
if sys.version_info[:2] >= (3, 8):
53-
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
54-
from importlib.metadata import PackageNotFoundError, version
55-
else:
56-
from importlib_metadata import PackageNotFoundError, version
56+
from importlib.metadata import PackageNotFoundError, version
5757

5858

5959
def _get_version(*names: str) -> str:
@@ -76,7 +76,7 @@ def _get_version(*names: str) -> str:
7676
DEFAULT_MEDIA_TYPE = "application/octet-stream"
7777

7878

79-
_OPTIONAL_HEADERS: Dict[str, str] = {
79+
_OPTIONAL_HEADERS: dict[str, str] = {
8080
"workflow_id": "Mex-WorkflowID",
8181
"filename": "Mex-FileName",
8282
"local_id": "Mex-LocalID",
@@ -89,7 +89,7 @@ def _get_version(*names: str) -> str:
8989
}
9090

9191

92-
def optional_header_map() -> Dict[str, str]:
92+
def optional_header_map() -> dict[str, str]:
9393
return _OPTIONAL_HEADERS.copy()
9494

9595

@@ -136,7 +136,7 @@ def optional_header_map() -> Dict[str, str]:
136136

137137
# urllib3 'futures' ( not part of 1.26 .. but available in 2.x )
138138
def reraise(
139-
tp: Optional[Type[BaseException]],
139+
tp: Optional[type[BaseException]],
140140
value: BaseException,
141141
tb: Optional[TracebackType] = None,
142142
) -> NoReturn:
@@ -195,7 +195,7 @@ def _looks_like_send_error(status_code: int, response_dict: dict) -> bool:
195195

196196
def _get_send_error_message(
197197
response_dict: dict,
198-
) -> Tuple[str, Union[SendMessageErrorResponse_v1, SendMessageErrorResponse_v2, dict]]:
198+
) -> tuple[str, Union[SendMessageErrorResponse_v1, SendMessageErrorResponse_v2, dict]]:
199199
if "errorDescription" in response_dict:
200200
return response_dict["errorDescription"], cast(SendMessageErrorResponse_v1, response_dict)
201201

@@ -243,7 +243,7 @@ def increment(
243243
class SSLContextAdapter(HTTPAdapter):
244244
def __init__(
245245
self,
246-
cert: Optional[Union[Tuple[str], Tuple[str, str], Tuple[str, str, str]]] = None,
246+
cert: Optional[Union[tuple[str], tuple[str, str], tuple[str, str, str]]] = None,
247247
verify: Optional[Union[str, bool]] = None,
248248
check_hostname: Optional[bool] = None,
249249
hostname_checks_common_name: Optional[bool] = None,
@@ -310,17 +310,17 @@ def __init__( # noqa: C901
310310
mailbox: str,
311311
password: str,
312312
shared_key: Optional[bytes] = None,
313-
cert: Optional[Union[Tuple[str], Tuple[str, str], Tuple[str, str, str]]] = None,
313+
cert: Optional[Union[tuple[str], tuple[str, str], tuple[str, str, str]]] = None,
314314
verify: Optional[Union[str, bool]] = None,
315315
check_hostname: Optional[bool] = None,
316316
hostname_checks_common_name: Optional[bool] = None,
317317
max_chunk_size=75 * 1024 * 1024,
318-
proxies: Optional[Dict[str, str]] = None,
318+
proxies: Optional[dict[str, str]] = None,
319319
transparent_compress: bool = False,
320320
max_retries: Union[int, Retry] = 3,
321321
retry_backoff_factor: Union[int, float] = 0.5,
322-
retry_status_force_list: Tuple[int, ...] = (425, 429, 502, 503, 504),
323-
retry_methods: Tuple[str, ...] = ("HEAD", "GET", "PUT", "POST", "DELETE", "OPTIONS", "TRACE"),
322+
retry_status_force_list: tuple[int, ...] = (425, 429, 502, 503, 504),
323+
retry_methods: tuple[str, ...] = ("HEAD", "GET", "PUT", "POST", "DELETE", "OPTIONS", "TRACE"),
324324
timeout: Union[int, float] = 10 * 60,
325325
application_name: Optional[str] = None,
326326
):
@@ -499,15 +499,15 @@ def lookup_endpoint(self, ods_code: str, workflow_id: str) -> EndpointLookupResp
499499
return cast(EndpointLookupResponse_v2, response.json())
500500

501501
def _inbox_v2_page(
502-
self, url: Optional[str] = None, params: Optional[Dict[str, Any]] = None
502+
self, url: Optional[str] = None, params: Optional[dict[str, Any]] = None
503503
) -> ListMessageResponse_v2:
504504
url = url or f"{self.mailbox_url}/inbox"
505505
response = self._session.get(url, timeout=self._timeout, params=params)
506506
response.raise_for_status()
507507

508508
return cast(ListMessageResponse_v2, response.json())
509509

510-
def list_messages(self, max_results: Optional[int] = None, workflow_filter: Optional[str] = None) -> List[str]:
510+
def list_messages(self, max_results: Optional[int] = None, workflow_filter: Optional[str] = None) -> list[str]:
511511
"""
512512
lists messages ids in the inbox; note if workflow_filter is set it's possible to receive an empty page
513513
when more results exist outside the first max_results
@@ -518,10 +518,10 @@ def list_messages(self, max_results: Optional[int] = None, workflow_filter: Opti
518518
workflow_filter (Optional[str]): workflow filter string
519519
520520
Returns:
521-
List[str]: message ids
521+
list[str]: message ids
522522
"""
523523

524-
params: Dict[str, Union[str, int]] = {}
524+
params: dict[str, Union[str, int]] = {}
525525
if max_results:
526526
if max_results < 10:
527527
raise ValueError("if set max_results should be >= 10")
@@ -532,7 +532,7 @@ def list_messages(self, max_results: Optional[int] = None, workflow_filter: Opti
532532

533533
result = self._inbox_v2_page(params=params)
534534

535-
return cast(List[str], result.get("messages", []))
535+
return cast(list[str], result.get("messages", []))
536536

537537
def retrieve_message(self, message_id: str) -> "Message":
538538
"""
@@ -572,7 +572,7 @@ def retrieve_message_chunk(self, message_id: str, chunk_num: int) -> Response:
572572
@staticmethod
573573
def _headers_for_chunk(
574574
recipient: str, chunk_num: int, total_chunks: int, compress: bool, **kwargs
575-
) -> Dict[str, str]:
575+
) -> dict[str, str]:
576576
if chunk_num > 1:
577577
headers = {
578578
"Content-Type": DEFAULT_MEDIA_TYPE,
@@ -793,7 +793,7 @@ def iterate_message_ids(
793793
Generator[str]: message ids
794794
"""
795795

796-
params: Dict[str, Union[int, str]] = {}
796+
params: dict[str, Union[int, str]] = {}
797797
if batch_size:
798798
if batch_size < 10:
799799
raise ValueError("if set batch_size should be >= 10")
@@ -802,9 +802,9 @@ def iterate_message_ids(
802802
if workflow_filter:
803803
params["workflow_filter"] = workflow_filter
804804

805-
def _next_messages(page_result: ListMessageResponse_v2) -> Tuple[Optional[str], List[str]]:
806-
return cast(Dict[str, str], page_result.get("links", {})).get("next"), cast(
807-
List[str], page_result.get("messages", [])
805+
def _next_messages(page_result: ListMessageResponse_v2) -> tuple[Optional[str], list[str]]:
806+
return cast(dict[str, str], page_result.get("links", {})).get("next"), cast(
807+
list[str], page_result.get("messages", [])
808808
)
809809

810810
result = self._inbox_v2_page(params=params)
@@ -941,7 +941,7 @@ class _BaseMessage:
941941
def __init__(self, msg_id: str, response, client):
942942
self._msg_id = msg_id
943943
self._client = client
944-
self._mex_headers: Dict[str, Any] = {}
944+
self._mex_headers: dict[str, Any] = {}
945945

946946
headers = response.headers
947947

@@ -994,7 +994,7 @@ def readline(self) -> bytes:
994994
"""
995995
return self._stream.readline()
996996

997-
def readlines(self) -> List[bytes]:
997+
def readlines(self) -> list[bytes]:
998998
"""
999999
Read all lines from the message
10001000
"""
@@ -1014,7 +1014,7 @@ def acknowledge(self):
10141014
"""
10151015
self._client.acknowledge_message(self._msg_id)
10161016

1017-
def mex_header(self, key: str, default: Optional[TDefault] = None) -> Union[str, TDefault]:
1017+
def mex_header(self, key: str, default: Optional[TDefault] = None) -> Union[str, Optional[TDefault]]:
10181018
"""get a mex header if present
10191019
10201020
Args:

mesh_client/io_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import warnings
55
import zlib
6-
from typing import List, cast
6+
from typing import cast
77

88

99
class IteratorMixin:
@@ -40,7 +40,7 @@ def readline(self) -> bytes:
4040
except StopIteration:
4141
return b""
4242

43-
def readlines(self) -> List[bytes]:
43+
def readlines(self) -> list[bytes]:
4444
return list(iter(self))
4545

4646

0 commit comments

Comments
 (0)