Skip to content

Commit

Permalink
Py38 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Sep 28, 2023
1 parent a629bd9 commit 3594c52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions clean_python/api_client/api_gateway.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import inject

from clean_python import Id
Expand All @@ -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:
Expand All @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions clean_python/api_client/api_provider.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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,
):
Expand All @@ -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)
Expand Down

0 comments on commit 3594c52

Please sign in to comment.