Skip to content

Commit 2574939

Browse files
authored
Fix linting errors (#13)
* Enable `ruff` and fix linting errors
1 parent cc6dc57 commit 2574939

39 files changed

+150
-141
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dev-deps: deps
1616

1717
fmt:
1818
ruff format $(SOURCES)
19-
ruff check $(SOURCES) --fix --unsafe-fixes
19+
ruff check --select I --fix $(SOURCES)
2020

2121
lint:
2222
dotenv-linter env.example

pyproject.toml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,56 @@ dev = [
3434

3535
[tool.ruff]
3636
line-length = 160
37+
src = ["src"]
3738

3839

39-
[tool.roof.lint]
40+
[tool.ruff.lint]
4041
select = ["ALL"]
42+
ignore = [
43+
"ANN101", # Missing type annotation for self in method
44+
"ANN102", # missing type annotation for `cls` in classmethod
45+
"ANN401", # dynamically typed expressions (typing.Any) are disallowed in `{}`
46+
"COM812", # Trailing comma missing
47+
"D100", # missing docstring in public module
48+
"D101", # missing docstring in public class
49+
"D102", # missing docstring in public method
50+
"D103", # missing docstring in public function
51+
"D104", # missing docstring in public package
52+
"D105", # missing docstring in magic method
53+
"D106", # missing docstring in public nested class
54+
"D107", # missing docstring in `__init__`
55+
"D203", # one blank line required before class docstring
56+
"D213", # Multi-line docstring summary should start at the second line
57+
"EM101", # exception must not use a string literal, assign to variable first
58+
"EM102", # expection must not use an f-string literal, assign to variable first
59+
"INP001", # file `%filename%` is part of an implicit namespace package. Add an `__init__.py`
60+
"ISC001", # implicitly concatenated string literals on one line
61+
"N818", # exception name `{}` should be named with an Error suffix
62+
"PT001", # use `@pytest.fixture()` over `@pytest.fixture`
63+
"TRY003", # avoid specifying long messages outside the exception class
64+
]
4165

4266

4367
[tool.ruff.lint.flake8-tidy-imports]
4468
ban-relative-imports = "all"
4569

4670

71+
[tool.ruff.lint.per-file-ignores]
72+
"**/tests/*" = [
73+
"ANN", # flake8-annotations
74+
"ARG001", # Unused function argument
75+
"PLR0913", # Too many arguments in function definition
76+
"PLR2004", # Magic value used in comparison, consider replacing `%value%` with a constant variable
77+
"S101", # Use of `assert` detected
78+
]
79+
"**/fixtures.py" = [
80+
"ANN", # flake8-annotations
81+
]
82+
83+
[tool.ruff.lint.isort]
84+
extra-standard-library = ["pytest"]
85+
86+
4787
[tool.pytest.ini_options]
4888
pythonpath = ["src"]
4989
testpaths = ["src"]

src/a12n/jwk_client.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import asyncio
2-
from dataclasses import dataclass
32
import json
43
import logging
4+
from dataclasses import dataclass
55

66
import httpx
77
import jwt
8-
from jwt.api_jwk import PyJWK
9-
from jwt.api_jwk import PyJWKSet
8+
from jwt.api_jwk import PyJWK, PyJWKSet
109
from jwt.api_jwt import decode_complete as decode_token
1110
from jwt.exceptions import PyJWKSetError
1211
from jwt.jwk_set_cache import JWKSetCache
1312

14-
1513
from app.types import DecodedValidToken
1614

17-
1815
logger = logging.getLogger(__name__)
1916

2017

@@ -24,7 +21,8 @@ class AsyncJWKClientException(Exception):
2421

2522
@dataclass
2623
class AsyncJWKClient:
27-
"""
24+
"""Async JW Keys client.
25+
2826
Inspired and partially copy-pasted from 'jwt.jwks_client.PyJWKClient'.
2927
The purpose is the same but querying the JWKS endpoint is async.
3028
"""
@@ -68,7 +66,7 @@ async def fetch_data(self) -> PyJWKSet:
6866
except PyJWKSetError as exc:
6967
raise AsyncJWKClientException(exc) from exc
7068

71-
async def get_jwk_set(self, refresh: bool = False) -> PyJWKSet:
69+
async def get_jwk_set(self, *, refresh: bool = False) -> PyJWKSet:
7270
jwk_set: PyJWKSet | None = None
7371

7472
while self.fetch_data_lock.locked():
@@ -82,8 +80,8 @@ async def get_jwk_set(self, refresh: bool = False) -> PyJWKSet:
8280

8381
return jwk_set
8482

85-
async def get_signing_keys(self, refresh: bool = False) -> list[PyJWK]:
86-
jwk_set = await self.get_jwk_set(refresh)
83+
async def get_signing_keys(self, *, refresh: bool = False) -> list[PyJWK]:
84+
jwk_set = await self.get_jwk_set(refresh=refresh)
8785

8886
signing_keys = [
8987
jwk_set_key
@@ -102,7 +100,7 @@ async def get_signing_keys(self, refresh: bool = False) -> list[PyJWK]:
102100
return signing_keys
103101

104102
async def get_signing_key(self, kid: str) -> PyJWK:
105-
signing_keys = await self.get_signing_keys()
103+
signing_keys = await self.get_signing_keys(refresh=False)
106104
signing_key = self.match_kid(signing_keys, kid)
107105

108106
if not signing_key:

src/a12n/tests/async_jwk_client/conftest.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

3-
from respx import MockRouter
4-
from respx import Route
3+
from respx import MockRouter, Route
54

65
from a12n.jwk_client import AsyncJWKClient
76

@@ -10,13 +9,13 @@
109

1110
@pytest.fixture
1211
def expired_token():
13-
return "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNMcjhuTjh1R29wUElMZlFvUGpfRCJ9.eyJpc3MiOiJodHRwczovL2Rldi1wcm50ZG1vMTYzc2NsczR4LnVzLmF1dGgwLmNvbS8iLCJhdWQiOiIxV1NiR1hGUnlhS0NsTHJvWHZteTlXdndrZUtHb1JvayIsImlhdCI6MTY5ODUyODU1OSwiZXhwIjoxNjk4NTI4ODU5LCJzdWIiOiJhdXRoMHw2NTNjMzI2MGEzMDQ0OGM1OTRhNjllMTIiLCJzaWQiOiI5MEZ3WFNDSFUtd0N3QmY0Y1YyQ3NZTnpBMldieDNUcSIsIm5vbmNlIjoiZTIxZWVhNTljNGY1MDg0N2Q3YzFhOGUzZjQ0NjVjYTcifQ.FO_xoMA9RGI7uAVauv00-zdORgkvCwyWfeAPd7lmU_nKzGp5avPa2MN66S0fjLKOxb8tgzrfpXYLUhDl1nqUvtj1A54-PfNW0n0ctdn2zk_CCOxsAjKyImlIgq7Y4DIuil0wikj7FdoWkB-bCBrKs7JaOoWkSHws9uQxRyvZzBwPHExW0myHWvB3G0x8g23PfSv2oALbvXBp0OAniGwru2Br9e2iXCVyGAUMTCpQmjPDAyfeYXGxF9BhxuX3e-GL80oyngBQK0kTxw-2Xz8LDSC-MI2jTs1gUo9qdVrg_1fzQtvAW9LGaWg5L_CJe92ZH3l1fBPfSh7Gc6uBtwF-YA"
12+
return "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNMcjhuTjh1R29wUElMZlFvUGpfRCJ9.eyJpc3MiOiJodHRwczovL2Rldi1wcm50ZG1vMTYzc2NsczR4LnVzLmF1dGgwLmNvbS8iLCJhdWQiOiIxV1NiR1hGUnlhS0NsTHJvWHZteTlXdndrZUtHb1JvayIsImlhdCI6MTY5ODUyODU1OSwiZXhwIjoxNjk4NTI4ODU5LCJzdWIiOiJhdXRoMHw2NTNjMzI2MGEzMDQ0OGM1OTRhNjllMTIiLCJzaWQiOiI5MEZ3WFNDSFUtd0N3QmY0Y1YyQ3NZTnpBMldieDNUcSIsIm5vbmNlIjoiZTIxZWVhNTljNGY1MDg0N2Q3YzFhOGUzZjQ0NjVjYTcifQ.FO_xoMA9RGI7uAVauv00-zdORgkvCwyWfeAPd7lmU_nKzGp5avPa2MN66S0fjLKOxb8tgzrfpXYLUhDl1nqUvtj1A54-PfNW0n0ctdn2zk_CCOxsAjKyImlIgq7Y4DIuil0wikj7FdoWkB-bCBrKs7JaOoWkSHws9uQxRyvZzBwPHExW0myHWvB3G0x8g23PfSv2oALbvXBp0OAniGwru2Br9e2iXCVyGAUMTCpQmjPDAyfeYXGxF9BhxuX3e-GL80oyngBQK0kTxw-2Xz8LDSC-MI2jTs1gUo9qdVrg_1fzQtvAW9LGaWg5L_CJe92ZH3l1fBPfSh7Gc6uBtwF-YA" # noqa: E501
1413

1514

1615
@pytest.fixture
1716
def token():
1817
# The token won't expire in ~100 years (expiration date 2123-10-05, it's more than enough to rely on it in test)
19-
return "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNMcjhuTjh1R29wUElMZlFvUGpfRCJ9.eyJpc3MiOiJodHRwczovL2Rldi1wcm50ZG1vMTYzc2NsczR4LnVzLmF1dGgwLmNvbS8iLCJhdWQiOiIxV1NiR1hGUnlhS0NsTHJvWHZteTlXdndrZUtHb1JvayIsImlhdCI6MTY5ODUyODE3MCwiZXhwIjo0ODUyMTI4MTcwLCJzdWIiOiJhdXRoMHw2NTNjMzI2MGEzMDQ0OGM1OTRhNjllMTIiLCJzaWQiOiI5MEZ3WFNDSFUtd0N3QmY0Y1YyQ3NZTnpBMldieDNUcSIsIm5vbmNlIjoiMTVhNWI2M2Y3MzI5MDcwMmU3MGViZmJlMDc5ODgxYmIifQ.FQYBaTnjKJHcskRl1WsB4kKQmyvXRcG8RDWlB2woSbzukZx7SnWghC1qRhYeqOLBUBpe3Iu_EzxgF26YDZJ28bKKNgL4fVmYak3jOg2nRP2lulrkF8USmkqT9Vx85hlIEVCisYOS6DJE0bHJL5WbHjCmDjQ6RGRyVZ3s6UPFXIwe2CMC_egAdWrsLYrgA1mqozQhwLJN2zSuObkDffkpHbX9XXB225v3-ryY-Rr0rPh9AOfKtEeMUEmNG0gsGyIbi0DoPDjAxlxCDx7ULVSChIKhUv4DKICqrqzHyopA7oE8LlpDbPTshQsL6L4u1EwUT7maP9VTcEQUTnp3Cu5msw"
18+
return "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjNMcjhuTjh1R29wUElMZlFvUGpfRCJ9.eyJpc3MiOiJodHRwczovL2Rldi1wcm50ZG1vMTYzc2NsczR4LnVzLmF1dGgwLmNvbS8iLCJhdWQiOiIxV1NiR1hGUnlhS0NsTHJvWHZteTlXdndrZUtHb1JvayIsImlhdCI6MTY5ODUyODE3MCwiZXhwIjo0ODUyMTI4MTcwLCJzdWIiOiJhdXRoMHw2NTNjMzI2MGEzMDQ0OGM1OTRhNjllMTIiLCJzaWQiOiI5MEZ3WFNDSFUtd0N3QmY0Y1YyQ3NZTnpBMldieDNUcSIsIm5vbmNlIjoiMTVhNWI2M2Y3MzI5MDcwMmU3MGViZmJlMDc5ODgxYmIifQ.FQYBaTnjKJHcskRl1WsB4kKQmyvXRcG8RDWlB2woSbzukZx7SnWghC1qRhYeqOLBUBpe3Iu_EzxgF26YDZJ28bKKNgL4fVmYak3jOg2nRP2lulrkF8USmkqT9Vx85hlIEVCisYOS6DJE0bHJL5WbHjCmDjQ6RGRyVZ3s6UPFXIwe2CMC_egAdWrsLYrgA1mqozQhwLJN2zSuObkDffkpHbX9XXB225v3-ryY-Rr0rPh9AOfKtEeMUEmNG0gsGyIbi0DoPDjAxlxCDx7ULVSChIKhUv4DKICqrqzHyopA7oE8LlpDbPTshQsL6L4u1EwUT7maP9VTcEQUTnp3Cu5msw" # noqa: E501
2019

2120

2221
@pytest.fixture
@@ -26,7 +25,7 @@ def matching_kid_data():
2625
{
2726
"kty": "RSA",
2827
"use": "sig",
29-
"n": "oIQkRCY4X-_ItMUPt65wVIGewOJfjMhlu6HG_rHik5-dTK0o6oyUne2Gevetn2Vrn8NSIaARobLZ8expuJBYDS121w_RloC6MCuzlc-j_nHj-BcBOCqGWPVwKX4un0HueD3aW3buqzYcmX_9LhdSE8ARyN0S9O6RbYWDCTKFhrRXtIP4wzP8vdPGXGurtGIiBbhVCK1LHG2lO5Gt8IIQ_DAcX6swnXCfbHwR1OXc9Do06o8c7ZsZdjMty5b4Fpv8rAKA-HTP_One4yhKtqCMYs3_gcTeQdHi-0w634VnpdzC_0f_MMzNIgvXC8VdJgkGpa6jLBp3mTqaFUdkAXFYlw",
28+
"n": "oIQkRCY4X-_ItMUPt65wVIGewOJfjMhlu6HG_rHik5-dTK0o6oyUne2Gevetn2Vrn8NSIaARobLZ8expuJBYDS121w_RloC6MCuzlc-j_nHj-BcBOCqGWPVwKX4un0HueD3aW3buqzYcmX_9LhdSE8ARyN0S9O6RbYWDCTKFhrRXtIP4wzP8vdPGXGurtGIiBbhVCK1LHG2lO5Gt8IIQ_DAcX6swnXCfbHwR1OXc9Do06o8c7ZsZdjMty5b4Fpv8rAKA-HTP_One4yhKtqCMYs3_gcTeQdHi-0w634VnpdzC_0f_MMzNIgvXC8VdJgkGpa6jLBp3mTqaFUdkAXFYlw", # noqa: E501
3029
"e": "AQAB",
3130
"kid": "3Lr8nN8uGopPILfQoPj_D",
3231
"x5t": "f93zLhSTsgVJiS9JA0x8sHkaLMg",
@@ -46,7 +45,7 @@ def not_matching_kid_data():
4645
{
4746
"kty": "RSA",
4847
"use": "sig",
49-
"n": "zB0xsH539lpLVejR6Hq1bHN3EzDt_0tJyr5JVHz3GSnNYAaZzkqL7HyLlhwttl7_bRyZJeZ8X6aasBxVK2JCDc9U-0KMJXmSoJs1oWYRo79DqdzCXK3ZYXcgkvI9OWF1qVx76vbZVwiRv5qUzpINdLnsX2CXChyd0LFkg14bYrSfdN-eMmG1PXtHZufeKG6HW17PFXS7OwesMQIfQ9kFfSvgFkJgkNM0o6NaeB-ZPDvzfKmmpBXjtGcze0A56NdQ7Z42DRDURROS82sPISrX-iAt93tZ1F0IW_U4niIYc6NFcWPPXpQpiVDDwdrz-L1H63mSUDSDFsWVcv2xWry6kQ",
48+
"n": "zB0xsH539lpLVejR6Hq1bHN3EzDt_0tJyr5JVHz3GSnNYAaZzkqL7HyLlhwttl7_bRyZJeZ8X6aasBxVK2JCDc9U-0KMJXmSoJs1oWYRo79DqdzCXK3ZYXcgkvI9OWF1qVx76vbZVwiRv5qUzpINdLnsX2CXChyd0LFkg14bYrSfdN-eMmG1PXtHZufeKG6HW17PFXS7OwesMQIfQ9kFfSvgFkJgkNM0o6NaeB-ZPDvzfKmmpBXjtGcze0A56NdQ7Z42DRDURROS82sPISrX-iAt93tZ1F0IW_U4niIYc6NFcWPPXpQpiVDDwdrz-L1H63mSUDSDFsWVcv2xWry6kQ", # noqa: E501
5049
"e": "AQAB",
5150
"kid": "ICOpsXGmpNaDPiljjRjiE",
5251
"x5t": "1GDK6kGV6HvZ1m_-VdSKIFNEtEU",

src/a12n/tests/async_jwk_client/tests_async_jwk_decode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import pytest
12
from contextlib import nullcontext as does_not_raise
3+
24
from a12n.jwk_client import AsyncJWKClientException
3-
import pytest
45

56
pytestmark = [
67
pytest.mark.usefixtures("mock_success_response"),

src/app/conf/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from app.conf.settings import get_app_settings
2-
from app.conf.settings import Settings
1+
from app.conf.settings import Settings, get_app_settings
32

43
__all__ = [
54
"Settings",

src/app/conf/settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from typing import Literal
33

44
from pydantic import AmqpDsn
5-
from pydantic_settings import BaseSettings
6-
from pydantic_settings import SettingsConfigDict
5+
from pydantic_settings import BaseSettings, SettingsConfigDict
76

87

98
class Settings(BaseSettings):
@@ -33,4 +32,4 @@ class Settings(BaseSettings):
3332

3433
@lru_cache
3534
def get_app_settings() -> Settings:
36-
return Settings() # type: ignore
35+
return Settings() # type: ignore[call-arg]

src/app/fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import pytest
2+
from collections.abc import Callable
23

34
from app.testing import MockedWebSocketServerProtocol
45

56

67
@pytest.fixture
7-
def create_ws():
8+
def create_ws() -> Callable[[], MockedWebSocketServerProtocol]:
89
return lambda: MockedWebSocketServerProtocol()
910

1011

1112
@pytest.fixture
12-
def ws(create_ws):
13+
def ws(create_ws) -> MockedWebSocketServerProtocol:
1314
return create_ws()
1415

1516

1617
@pytest.fixture
17-
def ya_ws(create_ws):
18+
def ya_ws(create_ws) -> MockedWebSocketServerProtocol:
1819
return create_ws()

src/app/services.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from abc import ABC
2-
from abc import abstractmethod
3-
from typing import Any, Callable
1+
from abc import ABC, abstractmethod
2+
from collections.abc import Callable
3+
from typing import Any
44

55

66
class BaseService(ABC):
7-
"""This is a template of a a base service.
7+
"""Template of a a base service.
8+
89
All services in the app should follow this rules:
910
* Input variables should be done at the __init__ phase
1011
* Service should implement a single entrypoint without arguments

src/app/testing.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def send(self, message: str) -> None: # type: ignore[override]
3333
await asyncio.sleep(0)
3434
await self.send_queue.put(message)
3535

36-
async def close(self, code: int = CloseCode.NORMAL_CLOSURE, reason: str = "") -> None:
36+
async def close(self, code: int = CloseCode.NORMAL_CLOSURE, reason: str = "") -> None: # noqa: ARG002
3737
self.state = State.CLOSED
3838

3939
async def wait_messages_to_be_sent(self) -> None:
@@ -46,10 +46,8 @@ async def count_sent_to_client(self) -> int:
4646
def client_send(self, message: dict) -> None:
4747
self.recv_queue.put_nowait(json.dumps(message))
4848

49-
async def client_recv(self, skip_count_first_messages=0) -> dict | None:
50-
"""Convenient for testing.
51-
Receive one message at time. First messages could be discarded with 'skip_count_first_messages' parameter.
52-
"""
49+
async def client_recv(self, skip_count_first_messages: int = 0) -> dict | None:
50+
"""Skip 'skip_count_first_messages' messages and return the next one. Convenient for testing."""
5351
await self.wait_messages_to_be_sent()
5452

5553
if self.send_queue.empty():

src/app/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import NewType, NamedTuple
1+
from typing import NamedTuple, NewType
22

33
UserId = NewType("UserId", str)
44
Event = NewType("Event", str)

src/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from app.conf import get_app_settings
3+
from app.conf import Settings, get_app_settings
44

55
pytest_plugins = [
66
"app.fixtures",
@@ -9,5 +9,5 @@
99

1010

1111
@pytest.fixture
12-
def settings():
12+
def settings() -> Settings:
1313
return get_app_settings()

src/consumer/consumer.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import asyncio
2-
from dataclasses import dataclass
32
import logging
3+
from dataclasses import dataclass
44
from typing import Protocol
55

66
import aio_pika
7+
import websockets
8+
from pydantic import ValidationError
79

810
from app import conf
9-
from consumer.dto import ConsumedMessage
10-
from consumer.dto import OutgoingMessage
11+
from consumer.dto import ConsumedMessage, OutgoingMessage
1112
from storage.subscription_storage import SubscriptionStorage
12-
from pydantic import ValidationError
13-
import websockets
14-
1513

1614
logger = logging.getLogger(__name__)
1715

@@ -61,7 +59,7 @@ def parse_message(raw_message: aio_pika.abc.AbstractIncomingMessage) -> Consumed
6159
try:
6260
return ConsumedMessage.model_validate_json(raw_message.body)
6361
except ValidationError as exc:
64-
logger.error("Consumed message not in expected format. Errors: %s", exc.errors())
62+
logger.error("Consumed message not in expected format. Errors: %s", exc.errors()) # noqa: TRY400
6563
return None
6664

6765
@staticmethod

src/consumer/dto.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from pydantic import BaseModel
2-
from pydantic import ConfigDict
31
from typing import Literal
2+
3+
from pydantic import BaseModel, ConfigDict
4+
45
from app.types import Event
56

67

src/consumer/tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
2+
from collections.abc import AsyncGenerator
3+
from contextlib import asynccontextmanager
4+
from dataclasses import dataclass
25

36
from consumer.consumer import Consumer
4-
from dataclasses import dataclass
5-
from contextlib import asynccontextmanager
6-
from typing import AsyncGenerator
77

88

99
@pytest.fixture(autouse=True)

src/consumer/tests/tests_consumer_on_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from contextlib import nullcontext as does_not_raise
21
import json
32
import pytest
3+
from contextlib import nullcontext as does_not_raise
44

55
from consumer.tests.conftest import MockedIncomingMessage
66

src/entrypoint.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import asyncio
2+
import logging
23
import signal
34

45
import websockets
5-
import logging
66

77
from app import conf
8-
from handlers import WebSocketsHandler
9-
from handlers import WebSocketsAccessGuardian
10-
from storage.subscription_storage import SubscriptionStorage
118
from consumer import Consumer
9+
from handlers import WebSocketsAccessGuardian, WebSocketsHandler
10+
from storage.subscription_storage import SubscriptionStorage
1211

1312
logging.basicConfig(level=logging.INFO)
1413

@@ -27,14 +26,16 @@ async def app_runner(
2726
consumer: Consumer,
2827
stop_signal: asyncio.Future,
2928
) -> None:
30-
async with websockets.serve(
31-
ws_handler=websockets_handler.websockets_handler,
32-
host=settings.WEBSOCKETS_HOST,
33-
port=settings.WEBSOCKETS_PORT,
29+
async with (
30+
websockets.serve(
31+
ws_handler=websockets_handler.websockets_handler,
32+
host=settings.WEBSOCKETS_HOST,
33+
port=settings.WEBSOCKETS_PORT,
34+
),
35+
asyncio.TaskGroup() as task_group,
3436
):
35-
async with asyncio.TaskGroup() as task_group:
36-
task_group.create_task(access_guardian.run(stop_signal))
37-
task_group.create_task(consumer.consume(stop_signal))
37+
task_group.create_task(access_guardian.run(stop_signal))
38+
task_group.create_task(consumer.consume(stop_signal))
3839

3940

4041
async def main() -> None:

0 commit comments

Comments
 (0)