Skip to content

Commit

Permalink
Replace Union and Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed Feb 3, 2025
1 parent 69367af commit 7340c90
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/azul/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Any,
Collection,
Mapping,
Optional,
Tuple,
Union,
cast,
)
from urllib.parse import (
Expand Down Expand Up @@ -68,11 +66,11 @@ class AzulConnection(Connection):
def perform_request(self,
method: str,
url: str,
params: Optional[Mapping[str, Any]] = None,
body: Optional[bytes] = None,
timeout: Optional[Union[int, float]] = None,
params: Mapping[str, Any] | None = None,
body: bytes | None = None,
timeout: int | float | None = None,
ignore: Collection[int] = (),
headers: Optional[Mapping[str, str]] = None
headers: Mapping[str, str] | None = None
) -> Tuple[int, Mapping[str, str], str]:
self._log_request(method, self._full_url(url, params), headers, body)
return super().perform_request(method, url, params, body, timeout, ignore, headers)
Expand All @@ -81,7 +79,7 @@ def log_request_success(self,
method: str,
full_url: str,
path: str,
body: Optional[bytes],
body: bytes | None,
status_code: int,
response: str,
duration: float
Expand All @@ -93,11 +91,11 @@ def log_request_fail(self,
method: str,
full_url: str,
path: str,
body: Optional[bytes],
body: bytes | None,
duration: float,
status_code: Optional[int] = None,
response: Optional[str] = None,
exception: Optional[Exception] = None
status_code: int | None = None,
response: str | None = None,
exception: Exception | None = None
) -> None:
self._log_response(logging.INFO if method == 'HEAD' and status_code == 404 else logging.WARN,
status_code, duration, full_url, method, response, exception)
Expand All @@ -109,7 +107,7 @@ def log_request_fail(self,
# is received, since it is only then that it is passed to our overrides of
# ``log_request_success`` and ``log_request_fail``.

def _full_url(self, url: str, params: Optional[Mapping[str, Any]]) -> str:
def _full_url(self, url: str, params: Mapping[str, Any] | None) -> str:
full_url = self.host + self.url_prefix + url
if params:
full_url = f'{full_url}?{urlencode(params)}'
Expand All @@ -124,11 +122,11 @@ def _log_request(self, method, full_url, headers, body):

def _log_response(self,
log_level: int,
status_code: Optional[int],
status_code: int | None,
duration: float,
full_url: str,
method: str,
response: Optional[str],
response: str | None,
exception=None
) -> None:
status_code = 'no' if status_code is None else status_code
Expand Down

0 comments on commit 7340c90

Please sign in to comment.