diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 24082c6..285869a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: exclude: '.bumpversion.cfg' - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: - id: ruff entry: ruff check src tests --fix --exit-non-zero-on-fix --show-fixes diff --git a/src/injection/providers/object.py b/src/injection/providers/object.py index 1f0bfec..cc1e4a5 100644 --- a/src/injection/providers/object.py +++ b/src/injection/providers/object.py @@ -1,7 +1,6 @@ -from typing import Any, TypeVar, Union, cast +from typing import Any, TypeVar, Union from injection.providers.base import BaseProvider -from injection.resolving import resolve_value T = TypeVar("T") @@ -12,12 +11,9 @@ def __init__(self, obj: T) -> None: self._obj = obj def _resolve(self) -> T: - value = cast(T, resolve_value(self._obj)) - return value + return self._obj - def __call__(self, **_: Any) -> Union[T, Any]: - # **_ - workaround for working DI with Litestar - # It's ok because there should be no arguments in the __call__ method + def __call__(self) -> Union[T, Any]: if self._mocks: return self._mocks[-1] return self._resolve() diff --git a/tests/container_objects.py b/tests/container_objects.py index f870d3b..d1632eb 100644 --- a/tests/container_objects.py +++ b/tests/container_objects.py @@ -67,7 +67,7 @@ class Container(DeclarativeContainer): ) service = providers.Transient(Service, redis_client=redis) some_service = providers.Singleton(SomeService, 1, redis, svc=service) - num = providers.Object(settings.provided.nested_settings.some_const) + num = providers.Object(1234) num2 = providers.Object(9402) callable_obj = providers.Callable(func, 1, c="string2", nums=num, d={"d": 500}) coroutine_provider = providers.Coroutine(coroutine, arg1=1, arg2=2) diff --git a/tests/test_base_container.py b/tests/test_base_container.py index 703a31f..f8d7615 100644 --- a/tests/test_base_container.py +++ b/tests/test_base_container.py @@ -50,7 +50,7 @@ def test_override_providers_success(container): assert container.num() == 999 assert not isinstance(container.redis(), Mock) - assert container.num() == 144 + assert container.num() == 1234 def test_container_instance_is_singleton(container): diff --git a/tests/test_e2e.py b/tests/test_e2e.py index 5d53d23..6a6e0c4 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -23,7 +23,7 @@ def test_e2e_success(container): assert container.some_service() is some_svc assert container.redis() is redis assert container.service() is not service - assert container.num() == 144 + assert container.num() == 1234 coroutine_result = asyncio.run(container.coroutine_provider()) assert coroutine_result == (1, 2) diff --git a/tests/test_providers/test_object.py b/tests/test_providers/test_object.py index 1dec4c1..4c9fd2c 100644 --- a/tests/test_providers/test_object.py +++ b/tests/test_providers/test_object.py @@ -18,6 +18,22 @@ class SomeClass: ... (234525, int), ], ) -def test_object_provider_resolving(obj, expected): +def test_object_provider_resolve_with_expected_type(obj, expected): provider = providers.Object(obj) + assert isinstance(provider(), expected) + + +@pytest.mark.parametrize( + ("obj", "expected"), + [ + (type, type), + (234525, 234525), + (object, object), + ("some_class", "some_class"), + ], +) +def test_object_provider_resolve_with_expected_value(obj, expected): + provider = providers.Object(obj) + + assert provider() == expected