Skip to content

Commit ba40f9e

Browse files
authored
feat: add type annotation in src and test folder (#87)
* type annotation * update type annotations * add type annotation in test
1 parent f9662f6 commit ba40f9e

27 files changed

+100
-98
lines changed

eventsourcingdb/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def __init__(
3030
self,
3131
base_url: str,
3232
api_token: str,
33-
):
33+
) -> None:
3434
self.__http_client = HttpClient(base_url=base_url, api_token=api_token)
3535

36-
async def __aenter__(self) -> "Client":
36+
async def __aenter__(self) -> 'Client':
3737
await self.__http_client.__aenter__()
3838
return self
3939

eventsourcingdb/container.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Container:
1313
def __init__(
1414
self,
15-
):
15+
) -> None:
1616
self._image_name: str = 'thenativeweb/eventsourcingdb'
1717
self._image_tag: str = 'latest'
1818
self._api_token: str = 'secret'
@@ -57,7 +57,7 @@ def _create_container(self) -> None:
5757
detach=True,
5858
) # type: ignore
5959

60-
def _extract_port_from_container_info(self, container_info):
60+
def _extract_port_from_container_info(self, container_info) -> int | None:
6161
port = None
6262
valid_mapping = True
6363
port_mappings = None
@@ -95,7 +95,7 @@ def _fetch_mapped_port(self) -> None:
9595
self._stop_and_remove_container()
9696
raise RuntimeError('Failed to determine mapped port')
9797

98-
def _get_container_info(self):
98+
def _get_container_info(self) -> dict | None:
9999
if self._container is None:
100100
return None
101101
return self._docker_client.api.inspect_container(self._container.id)
@@ -142,7 +142,7 @@ def _pull_or_get_image(self) -> None:
142142
except errors.APIError as e:
143143
self._handle_image_pull_error(e)
144144

145-
def _handle_image_pull_error(self, error):
145+
def _handle_image_pull_error(self, error) -> None:
146146
image_name = f"{self._image_name}:{self._image_tag}"
147147
try:
148148
self._docker_client.images.get(image_name)
@@ -211,7 +211,7 @@ def _check_endpoint_available(self, url: str) -> bool:
211211
return self._check_response_ok(response)
212212

213213
# pylint: disable=R6301
214-
def _check_response_ok(self, response) -> bool:
214+
def _check_response_ok(self, response: requests.Response) -> bool:
215215
return response is not None and response.status_code == HTTPStatus.OK
216216

217217
def with_api_token(self, token: str) -> 'Container':

eventsourcingdb/errors/client_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ClientError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Client error occurred: {cause}')

eventsourcingdb/errors/internal_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class InternalError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Internal error occurred: {cause}')

eventsourcingdb/errors/server_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ServerError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Server error occurred: {cause}')

eventsourcingdb/errors/validation_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class ValidationError(CustomError):
5-
def __init__(self, cause: str):
5+
def __init__(self, cause: str) -> None:
66
super().__init__(f'Validation error occurred: {cause}')

eventsourcingdb/event/event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from dataclasses import dataclass
3-
from typing import TypeVar
3+
from typing import TypeVar, Any
44

55
from ..errors.internal_error import InternalError
66
from ..errors.validation_error import ValidationError
@@ -24,7 +24,7 @@ class Event():
2424
trace_state: str | None = None
2525

2626
@staticmethod
27-
def parse(unknown_object: dict) -> "Event":
27+
def parse(unknown_object: dict) -> 'Event':
2828
source = unknown_object.get('source')
2929
if not isinstance(source, str):
3030
raise ValidationError(
@@ -103,7 +103,7 @@ def parse(unknown_object: dict) -> "Event":
103103
trace_state=trace_state
104104
)
105105

106-
def to_json(self):
106+
def to_json(self) -> dict[str, Any]:
107107
json = {
108108
'specversion': self.spec_version,
109109
'id': self.event_id,

eventsourcingdb/event/event_candidate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
2+
from typing import Any
33

44
@dataclass
55
class EventCandidate:
@@ -10,7 +10,7 @@ class EventCandidate:
1010
trace_parent: str | None = None
1111
trace_state: str | None = None
1212

13-
def to_json(self):
13+
def to_json(self) -> dict[str, Any]:
1414
json = {
1515
'data': self.data,
1616
'source': self.source,

eventsourcingdb/http_client/http_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def __init__(
1515
self,
1616
base_url: str,
1717
api_token: str,
18-
):
18+
) -> None:
1919
self.__base_url = base_url
2020
self.__api_token = api_token
2121
self.__session: ClientSession | None = None
2222

23-
async def __aenter__(self):
23+
async def __aenter__(self) -> 'HttpClient':
2424
await self.initialize()
2525
return self
2626

@@ -35,7 +35,7 @@ async def __aexit__(
3535
async def initialize(self) -> None:
3636
self.__session = aiohttp.ClientSession()
3737

38-
async def close(self):
38+
async def close(self) -> None:
3939
if self.__session is not None:
4040
await self.__session.close()
4141
self.__session = None

eventsourcingdb/http_client/response.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@
88

99

1010
class Response:
11-
def __init__(self, response: aiohttp.ClientResponse):
11+
def __init__(self, response: aiohttp.ClientResponse) -> None:
1212
self.__response: aiohttp.ClientResponse = response
1313

14-
async def __aenter__(self):
15-
# Properly await any async initialization if needed
14+
async def __aenter__(self) -> 'Response':
1615
return self
1716

18-
async def __aexit__(self, exc_type, exc_val, exc_tb):
17+
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
1918
if not self.__response.closed:
2019
self.__response.close()
2120

22-
def __enter__(self):
21+
def __enter__(self) -> 'Response':
2322
return self
2423

25-
def __exit__(self, exc_type, exc_val, exc_tb):
24+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
2625
if not self.__response.closed:
2726
self.__response.close()
2827

0 commit comments

Comments
 (0)