diff --git a/src/magic_di/_container.py b/src/magic_di/_container.py index bc9c60b..c05d953 100644 --- a/src/magic_di/_container.py +++ b/src/magic_di/_container.py @@ -69,7 +69,7 @@ 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: type[T] = functools.wraps(obj)(functools.partial(obj, *args, **kwargs)) # type: ignore[assignment] + partial: type[T] = functools.wraps(obj)(functools.partial(obj, *args, **kwargs)) return partial _instance: T | None = None diff --git a/src/magic_di/celery/__init__.py b/src/magic_di/celery/__init__.py index 87b2045..9406980 100644 --- a/src/magic_di/celery/__init__.py +++ b/src/magic_di/celery/__init__.py @@ -4,9 +4,9 @@ from ._task import BaseCeleryConnectableDeps, InjectableCeleryTask __all__ = ( - "InjectableCeleryTask", + "PROVIDE", "BaseCeleryConnectableDeps", - "get_celery_loader", "EventLoopGetter", - "PROVIDE", + "InjectableCeleryTask", + "get_celery_loader", ) diff --git a/src/magic_di/fastapi/__init__.py b/src/magic_di/fastapi/__init__.py index 1594aef..d55a689 100644 --- a/src/magic_di/fastapi/__init__.py +++ b/src/magic_di/fastapi/__init__.py @@ -5,4 +5,4 @@ from ._app import inject_app from ._provide import Provide # type: ignore[attr-defined] -__all__ = ("inject_app", "Provide") +__all__ = ("Provide", "inject_app") diff --git a/tests/conftest.py b/tests/conftest.py index 23728ce..da8a79e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ from typing import Protocol import pytest + from magic_di import Connectable, DependencyInjector @@ -68,6 +69,6 @@ class ServiceWithBindings: repo: RepoInterface -@pytest.fixture() +@pytest.fixture def injector() -> DependencyInjector: return DependencyInjector() diff --git a/tests/test_app.py b/tests/test_app.py index f21f637..3bb40c4 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -2,11 +2,11 @@ import pytest from fastapi import APIRouter, Depends, FastAPI +from starlette.testclient import TestClient + from magic_di import DependencyInjector from magic_di.fastapi import Provide, inject_app from magic_di.fastapi._provide import FastAPIInjectionError -from starlette.testclient import TestClient - from tests.conftest import Database, Service diff --git a/tests/test_celery.py b/tests/test_celery.py index a309f87..7f2322c 100644 --- a/tests/test_celery.py +++ b/tests/test_celery.py @@ -11,6 +11,8 @@ from celery import Celery from celery.bin.celery import celery # type: ignore[import-untyped] from fastapi import FastAPI +from starlette.testclient import TestClient + from magic_di import DependencyInjector from magic_di.celery import ( PROVIDE, @@ -18,8 +20,6 @@ InjectableCeleryTask, get_celery_loader, ) -from starlette.testclient import TestClient - from tests.conftest import AnotherDatabase, Service TEST_ERR_MSG = "TEST_ERR_MSG" @@ -153,7 +153,7 @@ def test_async_function_based_tasks( assert list(result) == [1010, "123", True] -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_sync_function_based_tasks( run_celery: Celery, service_ping_task_sync: InjectableCeleryTask, @@ -261,7 +261,7 @@ async def run(self, service: Service = PROVIDE) -> None: (True, True, [call(), call()]), ], ) -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_async_function_based_tasks_inside_event_loop( service_ping_task: InjectableCeleryTask, *, diff --git a/tests/test_healthcheck.py b/tests/test_healthcheck.py index a50d2cd..f5f0ec4 100644 --- a/tests/test_healthcheck.py +++ b/tests/test_healthcheck.py @@ -1,6 +1,7 @@ from dataclasses import dataclass import pytest + from magic_di import Connectable, DependencyInjector from magic_di.healthcheck import DependenciesHealthcheck @@ -27,7 +28,7 @@ async def __ping__(self) -> None: self.ping_count += 1 -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_healthcheck(injector: DependencyInjector) -> None: async def main(_: PingableService) -> None: ... diff --git a/tests/test_injector.py b/tests/test_injector.py index fd6ccc1..9e4adbd 100644 --- a/tests/test_injector.py +++ b/tests/test_injector.py @@ -4,9 +4,9 @@ from typing import Annotated, Any, Generic, TypeVar import pytest + from magic_di import Connectable, DependencyInjector, Injectable from magic_di.exceptions import InjectionError - from tests.conftest import ( AnotherDatabase, AsyncWorkers, @@ -20,7 +20,7 @@ ) -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_class_injection_success(injector: DependencyInjector) -> None: injected_service = injector.inject(Service)() assert not injected_service.is_alive() @@ -47,7 +47,7 @@ async def test_class_injection_success(injector: DependencyInjector) -> None: assert not injected_service.workers.connected -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_function_injection_success(injector: DependencyInjector) -> None: def run_service(service: Service) -> Service: return service @@ -61,7 +61,7 @@ def run_service(service: Service) -> Service: assert isinstance(service, Service) -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_function_injection_success_legacy_optional(injector: DependencyInjector) -> None: def run_service(service: Service | None) -> Service: assert service is not None @@ -81,7 +81,7 @@ def test_class_injection_missing_class(injector: DependencyInjector) -> None: injector.inject(BrokenService) -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_class_injection_with_bindings(injector: DependencyInjector) -> None: injector.bind({RepoInterface: Repository}) diff --git a/tests/test_utils.py b/tests/test_utils.py index 070d5fe..9d58448 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,6 @@ from magic_di import ConnectableProtocol, DependencyInjector from magic_di.utils import inject_and_run - from tests.conftest import Repository