Skip to content

Commit

Permalink
feat(MyPy): WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed Oct 26, 2023
1 parent 7c4d082 commit 1bf8315
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion sinch/core/adapters/asyncio_http_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from sinch.core.ports.http_transport import AsyncHTTPTransport, HttpRequest
from sinch.core.endpoint import HTTPEndpoint
from sinch.core.models.http_response import HTTPResponse
from sinch.core.models.base_model import SinchBaseModel


class HTTPTransportAioHTTP(AsyncHTTPTransport):
async def request(self, endpoint: HTTPEndpoint) -> HTTPResponse:
async def request(self, endpoint: HTTPEndpoint) -> SinchBaseModel:
request_data: HttpRequest = self.prepare_request(endpoint)
request_data_with_auth: HttpRequest = await self.authenticate(endpoint, request_data)

Expand Down
6 changes: 3 additions & 3 deletions sinch/core/ports/http_transport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import aiohttp
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from typing import Optional, TYPE_CHECKING, Union, Any, Coroutine
from sinch.core.endpoint import HTTPEndpoint
from sinch.core.models.http_request import HttpRequest
from sinch.core.models.http_response import HTTPResponse
Expand All @@ -17,7 +17,7 @@ def __init__(self, sinch: 'ClientBase'):
self.sinch = sinch

@abstractmethod
def request(self, endpoint: HTTPEndpoint) -> SinchBaseModel:
def request(self, endpoint: HTTPEndpoint) -> Union[SinchBaseModel, Coroutine[Any, Any, SinchBaseModel]]:
pass

def authenticate(self, endpoint: HTTPEndpoint, request_data: HttpRequest) -> HttpRequest:
Expand Down Expand Up @@ -74,7 +74,7 @@ async def authenticate(self, endpoint: HTTPEndpoint, request_data: HttpRequest)

return request_data

async def handle_response(self, endpoint: HTTPEndpoint, http_response: HTTPResponse) -> HTTPResponse:
async def handle_response(self, endpoint: HTTPEndpoint, http_response: HTTPResponse) -> SinchBaseModel:
if http_response.status_code == 401:
self.sinch.configuration.token_manager.handle_invalid_token(http_response)
if self.sinch.configuration.token_manager.token_state == TokenState.EXPIRED:
Expand Down
4 changes: 2 additions & 2 deletions sinch/core/token_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum
from abc import ABC, abstractmethod
from typing import Optional, TYPE_CHECKING, Union, Any
from typing import Optional, TYPE_CHECKING, Union, Any, Coroutine

from sinch.domains.authentication.models.authentication import OAuthToken
from sinch.domains.authentication.endpoints.oauth import OAuthEndpoint
Expand All @@ -24,7 +24,7 @@ def __init__(self, sinch: 'ClientBase') -> None:
self.token_state = TokenState.INVALID

@abstractmethod
def get_auth_token(self) -> Optional[OAuthToken]:
def get_auth_token(self) -> Union[Optional[OAuthToken], Coroutine[Any, Any, Optional[OAuthToken]]]:
pass

def invalidate_expired_token(self) -> None:
Expand Down

0 comments on commit 1bf8315

Please sign in to comment.