Skip to content

Commit 63773ed

Browse files
authored
Merge pull request #25 from jhnnsrs:typing
feat: Refactor and enhance type hints across multiple modules
2 parents 08dd167 + 03b8c54 commit 63773ed

23 files changed

+351
-442
lines changed

rath/contrib/fakts/__init__.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

rath/contrib/fakts/links/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

rath/contrib/fakts/links/aiohttp.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

rath/contrib/fakts/links/graphql_ws.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

rath/contrib/fakts/links/httpx.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

rath/contrib/fakts/links/subscription_transport_ws.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

rath/contrib/herre/links/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

rath/contrib/herre/links/auth.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

rath/links/aiohttp.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from http import HTTPStatus
33
import json
44
from ssl import SSLContext
5-
from typing import Any, Dict, List, Optional, Type, AsyncIterator
5+
from typing import Any, Dict, List, Optional, Self, Type, AsyncIterator
66
from rath.links.types import Payload
77
import aiohttp
88
from graphql import OperationType
@@ -43,7 +43,11 @@ class AIOHttpLink(AsyncTerminatingLink):
4343
"""ssl_context is the SSLContext to use for the aiohttp session. By default, this
4444
is a context that uses the certifi CA bundle."""
4545

46-
auth_errors: List[HTTPStatus] = Field(default_factory=lambda: (HTTPStatus.FORBIDDEN,))
46+
auth_errors: List[HTTPStatus] = Field(
47+
default_factory=lambda: [
48+
HTTPStatus.FORBIDDEN,
49+
]
50+
)
4751
"""auth_errors is a list of HTTPStatus codes that indicate that the request was
4852
unauthorized. By default, this is just HTTPStatus.FORBIDDEN, but you can
4953
override this to include other status codes that indicate that the request was
@@ -56,9 +60,9 @@ class AIOHttpLink(AsyncTerminatingLink):
5660

5761
_connected = False
5862

59-
async def __aenter__(self) -> None:
63+
async def __aenter__(self) -> Self:
6064
"""Entery point for the async context manager"""
61-
pass
65+
return self
6266

6367
async def aconnect(self, operation: Operation) -> None:
6468
"""Connects the link to the server
@@ -69,7 +73,12 @@ async def aconnect(self, operation: Operation) -> None:
6973
"""
7074
self._connected = True
7175

72-
async def __aexit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], traceback: Optional[Any]) -> None:
76+
async def __aexit__(
77+
self,
78+
exc_type: Optional[Type[BaseException]],
79+
exc_val: Optional[BaseException],
80+
traceback: Optional[Any],
81+
) -> None:
7382
"""Exit point for the async context manager"""
7483
pass
7584

rath/links/base.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, AsyncIterator, Optional, Type
1+
from typing import Any, AsyncIterator, Optional, Self, Type
22
from koil.composition import KoiledModel
33
from rath.operation import GraphQLResult, Operation
44
from rath.errors import NotComposedError
@@ -23,18 +23,25 @@ async def adisconnect(self) -> None:
2323
"""A coroutine that is called when the link is disconnected."""
2424
pass
2525

26-
async def __aenter__(self) -> None:
26+
async def __aenter__(self) -> Self:
2727
"""A coroutine that is called when the link is entered."""
28-
pass
29-
30-
async def __aexit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], traceback: Optional[Any]) -> None:
28+
return self
29+
30+
async def __aexit__(
31+
self,
32+
exc_type: Optional[Type[BaseException]],
33+
exc_val: Optional[BaseException],
34+
traceback: Optional[Any],
35+
) -> None:
3136
"""A coroutine that is called when the link is exited."""
3237
pass
3338

3439
def aexecute(self, operation: Operation) -> AsyncIterator[GraphQLResult]:
3540
"""A coroutine that takes an operation and returns an AsyncIterator
3641
of GraphQLResults. This method should be implemented by subclasses."""
37-
raise NotImplementedError(f"Please overwrite the asubscribe method in {self.__class__.__name__}")
42+
raise NotImplementedError(
43+
f"Please overwrite the asubscribe method in {self.__class__.__name__}"
44+
)
3845

3946

4047
class TerminatingLink(Link):

0 commit comments

Comments
 (0)