From 9c3f3ff100cc23b11bc98b408c3b87b9e8ba14a6 Mon Sep 17 00:00:00 2001 From: Nikita Zavadin Date: Fri, 20 Sep 2024 13:22:19 +0200 Subject: [PATCH] Fmt --- src/magic_di/_container.py | 8 ++++---- src/magic_di/_injector.py | 2 +- src/magic_di/healthcheck.py | 8 ++++---- tests/test_healthcheck.py | 8 +++----- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/magic_di/_container.py b/src/magic_di/_container.py index 3e419d1..bc9c60b 100644 --- a/src/magic_di/_container.py +++ b/src/magic_di/_container.py @@ -4,7 +4,7 @@ import inspect from dataclasses import dataclass from threading import Lock -from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast +from typing import TYPE_CHECKING, Any, Generic, TypeVar if TYPE_CHECKING: from collections.abc import Iterable @@ -69,8 +69,8 @@ def _get(self, obj: type[T]) -> type[T] | None: def _wrap(obj: type[T], *args: Any, **kwargs: Any) -> type[T]: if not inspect.isclass(obj): - partial = functools.wraps(obj)(functools.partial(obj, *args, **kwargs)) - return cast(type[T], partial) + partial: type[T] = functools.wraps(obj)(functools.partial(obj, *args, **kwargs)) # type: ignore[assignment] + return partial _instance: T | None = None @@ -98,7 +98,7 @@ def new(_: Any) -> T: # # Here we manually create a new singleton class factory using the `type` metaclass # Since the original class was not modified, it will use its own metaclass. - return functools.wraps( + return functools.wraps( # type: ignore[return-value] obj, updated=(), )( diff --git a/src/magic_di/_injector.py b/src/magic_di/_injector.py index 8c9ac67..61aca0c 100644 --- a/src/magic_di/_injector.py +++ b/src/magic_di/_injector.py @@ -133,7 +133,7 @@ def inspect(self, obj: AnyObject) -> Signature[AnyObject]: else: signature.deps[name] = hint - except Exception as exc: # noqa: BLE001 + except Exception as exc: raise InspectionError(obj) from exc return signature diff --git a/src/magic_di/healthcheck.py b/src/magic_di/healthcheck.py index bf03b50..8dff918 100644 --- a/src/magic_di/healthcheck.py +++ b/src/magic_di/healthcheck.py @@ -1,14 +1,13 @@ import asyncio from asyncio import Future from dataclasses import dataclass -from typing import Protocol, Any +from typing import Any, Protocol -from magic_di import DependencyInjector, ConnectableProtocol, Connectable +from magic_di import Connectable, ConnectableProtocol, DependencyInjector class PingableProtocol(ConnectableProtocol, Protocol): - async def __ping__(self) -> None: - ... + async def __ping__(self) -> None: ... @dataclass @@ -27,6 +26,7 @@ async def main(redis: Redis, deps_healthcheck: DependenciesHealthcheck) -> None: inject_and_run(main) ``` """ + injector: DependencyInjector async def ping_dependencies(self, max_concurrency: int = 1) -> None: diff --git a/tests/test_healthcheck.py b/tests/test_healthcheck.py index 2d719cb..a50d2cd 100644 --- a/tests/test_healthcheck.py +++ b/tests/test_healthcheck.py @@ -1,7 +1,6 @@ from dataclasses import dataclass import pytest - from magic_di import Connectable, DependencyInjector from magic_di.healthcheck import DependenciesHealthcheck @@ -30,8 +29,7 @@ async def __ping__(self) -> None: @pytest.mark.asyncio() async def test_healthcheck(injector: DependencyInjector) -> None: - async def main(_: PingableService) -> None: - ... + async def main(_: PingableService) -> None: ... await injector.inject(main)() @@ -53,6 +51,6 @@ async def main(_: PingableService) -> None: await healthcheck.ping_dependencies(max_concurrency=3) - assert injected_db.ping_count == 2 - assert injected_srv.ping_count == 2 + assert injected_db.ping_count == 2 # noqa: PLR2004 + assert injected_srv.ping_count == 2.0 # noqa: PLR2004 assert injected_srv_not_pingable.ping_count == 0