Skip to content

Commit 9e5a959

Browse files
committed
mypy
1 parent ec5e3ae commit 9e5a959

File tree

10 files changed

+21
-27
lines changed

10 files changed

+21
-27
lines changed

packages/service-library/src/servicelib/aiohttp/application_setup.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717

1818
log = logging.getLogger(__name__)
1919

20-
APP_SETUP_COMPLETED_KEY = f"{__name__ }.setup"
20+
APP_SETUP_COMPLETED_KEY = f"{__name__}.setup"
2121

2222

2323
class _SetupFunc(Protocol):
2424
__name__: str
2525

26-
def __call__(self, app: web.Application, *args: Any, **kwds: Any) -> bool:
27-
...
26+
def __call__(self, app: web.Application, *args: Any, **kwds: Any) -> bool: ...
2827

2928

3029
class _ApplicationSettings(Protocol):
31-
def is_enabled(self, field_name: str) -> bool:
32-
...
30+
def is_enabled(self, field_name: str) -> bool: ...
3331

3432

3533
class ModuleCategory(Enum):
@@ -46,12 +44,10 @@ def __init__(self, *, reason) -> None:
4644
super().__init__(reason)
4745

4846

49-
class ApplicationSetupError(Exception):
50-
...
47+
class ApplicationSetupError(Exception): ...
5148

5249

53-
class DependencyError(ApplicationSetupError):
54-
...
50+
class DependencyError(ApplicationSetupError): ...
5551

5652

5753
class SetupMetadataDict(TypedDict):
@@ -91,9 +87,9 @@ def _is_addon_enabled_from_config(
9187
cfg: dict[str, Any], dotted_section: str, section
9288
) -> bool:
9389
try:
94-
parts: list[str] = dotted_section.split(".")
90+
parts = dotted_section.split(".")
9591
# navigates app_config (cfg) searching for section
96-
searched_config = deepcopy(cfg)
92+
searched_config: Any = deepcopy(cfg)
9793
for part in parts:
9894
if section and part == "enabled":
9995
# if section exists, no need to explicitly enable it
@@ -278,7 +274,7 @@ def _wrapper(app: web.Application, *args, **kargs) -> bool:
278274

279275
# post-setup
280276
if completed is None:
281-
completed = True
277+
completed = True # type: ignore[unreachable]
282278

283279
if completed: # registers completed setup
284280
app[APP_SETUP_COMPLETED_KEY].append(module_name)

packages/service-library/src/servicelib/aiohttp/docker_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ async def retrieve_image_layer_information(
9797
return TypeAdapter(DockerImageManifestsV2).validate_python(
9898
json_response
9999
)
100-
return None
100+
return None # type: ignore[unreachable]

packages/service-library/src/servicelib/deferred_tasks/_deferred_manager.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def __init__(
122122
max_workers: NonNegativeInt = _DEFAULT_DEFERRED_MANAGER_WORKER_SLOTS,
123123
delay_when_requeuing_message: timedelta = _DEFAULT_DELAY_BEFORE_NACK,
124124
) -> None:
125-
126125
self._task_tracker: BaseTaskTracker = RedisTaskTracker(scheduler_redis_sdk)
127126

128127
self._worker_tracker = WorkerTracker(max_workers)
@@ -216,7 +215,7 @@ def un_patch_base_deferred_handlers(cls) -> None:
216215
)
217216

218217
if isinstance(subclass.start, _PatchStartDeferred):
219-
with log_context(
218+
with log_context( # type: ignore[unreachable]
220219
_logger,
221220
logging.DEBUG,
222221
f"Remove `start` patch for {class_unique_reference}",
@@ -345,7 +344,6 @@ async def __get_task_schedule(
345344
async def _fs_handle_scheduled( # pylint:disable=method-hidden
346345
self, task_uid: TaskUID
347346
) -> None:
348-
349347
_log_state(TaskState.SCHEDULED, task_uid)
350348

351349
task_schedule = await self.__get_task_schedule(
@@ -425,7 +423,7 @@ async def _fs_handle_worker( # pylint:disable=method-hidden
425423
await self.__publish_to_queue(task_uid, _FastStreamRabbitQueue.ERROR_RESULT)
426424
return
427425

428-
msg = (
426+
msg = ( # type: ignore[unreachable]
429427
f"Unexpected state, result type={type(task_schedule.result)} should be an instance "
430428
f"of {TaskResultSuccess.__name__}, {TaskResultError.__name__} or {TaskResultCancelledError.__name__}"
431429
)

packages/service-library/src/servicelib/fastapi/docker_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def retrieve_image_layer_information(
104104
return TypeAdapter(DockerImageManifestsV2).validate_python(
105105
json_response
106106
)
107-
return None
107+
return None # type: ignore[unreachable]
108108

109109

110110
async def pull_images(
@@ -130,7 +130,6 @@ async def pull_images(
130130
progress_unit="Byte",
131131
description=f"pulling {len(images)} images",
132132
) as pbar:
133-
134133
await asyncio.gather(
135134
*[
136135
pull_image(

packages/service-library/src/servicelib/fastapi/lifespan_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def is_lifespan_called(state: State, lifespan_name: str) -> bool:
3737
# Valid signatures include: `()`, `(app)`, `(app, state)`, or even `(_, state)`.
3838
# It's easy to accidentally swap or misplace these arguments.
3939
assert not isinstance( # nosec
40-
state, FastAPI
40+
state, # type: ignore[unreachable]
41+
FastAPI,
4142
), "Did you swap arguments? `lifespan(app, state)` expects (app: FastAPI, state: State)"
4243

4344
called_lifespans = state.get(_CALLED_LIFESPANS_KEY, set())

packages/service-library/src/servicelib/pools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
from collections.abc import Iterator
12
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
23
from contextlib import contextmanager
3-
from typing import Iterator
44

55
# only gets created on use and is guaranteed to be the s
66
# ame for the entire lifetime of the application
7-
__shared_process_pool_executor = {}
8-
__shared_thread_pool_executor = {}
7+
__shared_process_pool_executor: dict[str, ProcessPoolExecutor] = {}
8+
__shared_thread_pool_executor: dict[str, ThreadPoolExecutor] = {}
99

1010

1111
def _get_shared_process_pool_executor(**kwargs) -> ProcessPoolExecutor:

packages/service-library/src/servicelib/rabbitmq/_client_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def ping(self) -> bool:
6767
async with await aio_pika.connect(self.settings.dsn, timeout=1):
6868
...
6969
return True
70-
return False
70+
return False # type: ignore[unreachable]
7171

7272
@abstractmethod
7373
async def close(self) -> None: ...

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/pricing_plans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def list_connected_services_to_pricing_plan_by_pricing_plan(
114114
product_name: ProductName,
115115
pricing_plan_id: PricingPlanId,
116116
) -> list[PricingPlanToServiceGet]:
117-
result: RutPricingPlanGet = await rabbitmq_rpc_client.request(
117+
result = await rabbitmq_rpc_client.request(
118118
RESOURCE_USAGE_TRACKER_RPC_NAMESPACE,
119119
_RPC_METHOD_NAME_ADAPTER.validate_python(
120120
"list_connected_services_to_pricing_plan_by_pricing_plan"

packages/service-library/src/servicelib/redis/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def ping(self) -> bool:
9999
# NOTE: retry_* input parameters from aioredis.from_url do not apply for the ping call
100100
await self._client.ping()
101101
return True
102-
return False
102+
return False # type: ignore[unreachable]
103103

104104
@property
105105
def is_healthy(self) -> bool:

packages/service-library/src/servicelib/rest_responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def is_enveloped(payload: Mapping | str) -> bool:
2525
return is_enveloped_from_map(payload)
2626
if isinstance(payload, str):
2727
return is_enveloped_from_text(text=payload)
28-
return False
28+
return False # type: ignore[unreachable]
2929

3030

3131
def unwrap_envelope(payload: Mapping[str, Any]) -> tuple:

0 commit comments

Comments
 (0)