Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre-commit errors for main branch #21

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/magic_di/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/magic_di/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from ._task import BaseCeleryConnectableDeps, InjectableCeleryTask

__all__ = (
"InjectableCeleryTask",
"PROVIDE",
"BaseCeleryConnectableDeps",
"get_celery_loader",
"EventLoopGetter",
"PROVIDE",
"InjectableCeleryTask",
"get_celery_loader",
)
2 changes: 1 addition & 1 deletion src/magic_di/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Protocol

import pytest

from magic_di import Connectable, DependencyInjector


Expand Down Expand Up @@ -68,6 +69,6 @@ class ServiceWithBindings:
repo: RepoInterface


@pytest.fixture()
@pytest.fixture
def injector() -> DependencyInjector:
return DependencyInjector()
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 4 additions & 4 deletions tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
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,
BaseCeleryConnectableDeps,
InjectableCeleryTask,
get_celery_loader,
)
from starlette.testclient import TestClient

from tests.conftest import AnotherDatabase, Service

TEST_ERR_MSG = "TEST_ERR_MSG"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
*,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_healthcheck.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass

import pytest

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

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

Expand Down
10 changes: 5 additions & 5 deletions tests/test_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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})

Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from magic_di import ConnectableProtocol, DependencyInjector
from magic_di.utils import inject_and_run

from tests.conftest import Repository


Expand Down
Loading