From 3594c52305e5380069ac9b984012654e1e6cbd74 Mon Sep 17 00:00:00 2001 From: Casper van der Wel Date: Thu, 28 Sep 2023 16:54:53 +0200 Subject: [PATCH] Py38 compat --- clean_python/api_client/api_gateway.py | 6 ++++-- clean_python/api_client/api_provider.py | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/clean_python/api_client/api_gateway.py b/clean_python/api_client/api_gateway.py index 52aedf4..6cfaf8c 100644 --- a/clean_python/api_client/api_gateway.py +++ b/clean_python/api_client/api_gateway.py @@ -1,3 +1,5 @@ +from typing import Optional + import inject from clean_python import Id @@ -12,7 +14,7 @@ class SyncApiGateway(SyncGateway): path: str - def __init__(self, provider_override: SyncApiProvider | None = None): + def __init__(self, provider_override: Optional[SyncApiProvider] = None): self.provider_override = provider_override def __init_subclass__(cls, path: str) -> None: @@ -25,7 +27,7 @@ def __init_subclass__(cls, path: str) -> None: def provider(self) -> SyncApiProvider: return self.provider_override or inject.instance(SyncApiProvider) - def get(self, id: Id) -> Json | None: + def get(self, id: Id) -> Optional[Json]: return self.provider.request("GET", self.path.format(id=id)) def add(self, item: Json) -> Json: diff --git a/clean_python/api_client/api_provider.py b/clean_python/api_client/api_provider.py index d7e2862..d44db5a 100644 --- a/clean_python/api_client/api_provider.py +++ b/clean_python/api_client/api_provider.py @@ -1,5 +1,6 @@ from http import HTTPStatus from typing import Callable +from typing import Optional from urllib.parse import urlencode from urllib.parse import urljoin @@ -30,7 +31,7 @@ def join(url: str, path: str) -> str: return result -def add_query_params(url: str, params: Json | None) -> str: +def add_query_params(url: str, params: Optional[Json]) -> str: if params is None: return url return url + "?" + urlencode(params, doseq=True) @@ -51,7 +52,7 @@ class SyncApiProvider: def __init__( self, url: AnyHttpUrl, - fetch_token: Callable[[PoolManager, int], str | None], + fetch_token: Callable[[PoolManager, int], Optional[str]], retries: int = 3, backoff_factor: float = 1.0, ): @@ -64,11 +65,11 @@ def request( self, method: str, path: str, - params: Json | None = None, - json: Json | None = None, - fields: Json | None = None, + params: Optional[Json] = None, + json: Optional[Json] = None, + fields: Optional[Json] = None, timeout: float = 5.0, - ) -> Json | None: + ) -> Optional[Json]: assert ctx.tenant is not None url = join(self._url, path) token = self._fetch_token(self._pool, ctx.tenant.id)