Skip to content

Commit

Permalink
Fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
RB387 committed Sep 20, 2024
1 parent 7508c83 commit 9c3f3ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/magic_di/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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=(),
)(
Expand Down
2 changes: 1 addition & 1 deletion src/magic_di/_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/magic_di/healthcheck.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions tests/test_healthcheck.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from dataclasses import dataclass

import pytest

from magic_di import Connectable, DependencyInjector
from magic_di.healthcheck import DependenciesHealthcheck

Expand Down Expand Up @@ -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)()

Expand All @@ -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

0 comments on commit 9c3f3ff

Please sign in to comment.