From f275a2463e8e8ac1338f0518d329034d0038b567 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Thu, 9 Jan 2025 09:27:27 +0300 Subject: [PATCH] remove deprecated (#137) --- tests/test_deprecated.py | 24 --------------------- that_depends/container.py | 6 ------ that_depends/providers/__init__.py | 5 +---- that_depends/providers/context_resources.py | 12 ----------- that_depends/providers/resources.py | 12 ----------- 5 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 tests/test_deprecated.py diff --git a/tests/test_deprecated.py b/tests/test_deprecated.py deleted file mode 100644 index fdb8be1..0000000 --- a/tests/test_deprecated.py +++ /dev/null @@ -1,24 +0,0 @@ -import logging - -import pytest - -from that_depends import BaseContainer, providers - - -logger = logging.getLogger(__name__) - - -class DIContainer(BaseContainer): - pass - - -async def test_init_async_resources() -> None: - await DIContainer.init_async_resources() - - -def test_wrong_deprecated_providers_init() -> None: - with pytest.raises(TypeError, match="Unsupported resource type"): - providers.AsyncContextResource(lambda: None) # type: ignore[arg-type,return-value] - - with pytest.raises(TypeError, match="Unsupported resource type"): - providers.AsyncResource(lambda: None) # type: ignore[arg-type,return-value] diff --git a/that_depends/container.py b/that_depends/container.py index c4f9739..45b3d16 100644 --- a/that_depends/container.py +++ b/that_depends/container.py @@ -1,6 +1,5 @@ import inspect import typing -import warnings from contextlib import contextmanager from that_depends.providers import AbstractProvider, Resource, Singleton @@ -57,11 +56,6 @@ async def init_resources(cls) -> None: for container in cls.get_containers(): await container.init_resources() - @classmethod - async def init_async_resources(cls) -> None: - warnings.warn("init_async_resources is deprecated, use init_resources instead", RuntimeWarning, stacklevel=1) - await cls.init_resources() - @classmethod async def tear_down(cls) -> None: for provider in reversed(cls.get_providers().values()): diff --git a/that_depends/providers/__init__.py b/that_depends/providers/__init__.py index 6e5d4b5..78d8852 100644 --- a/that_depends/providers/__init__.py +++ b/that_depends/providers/__init__.py @@ -1,23 +1,20 @@ from that_depends.providers.base import AbstractProvider, AttrGetter from that_depends.providers.collections import Dict, List from that_depends.providers.context_resources import ( - AsyncContextResource, ContextResource, DIContextMiddleware, container_context, ) from that_depends.providers.factories import AsyncFactory, Factory from that_depends.providers.object import Object -from that_depends.providers.resources import AsyncResource, Resource +from that_depends.providers.resources import Resource from that_depends.providers.selector import Selector from that_depends.providers.singleton import AsyncSingleton, Singleton __all__ = [ "AbstractProvider", - "AsyncContextResource", "AsyncFactory", - "AsyncResource", "AsyncSingleton", "AttrGetter", "ContextResource", diff --git a/that_depends/providers/context_resources.py b/that_depends/providers/context_resources.py index 12ebd5a..6d865b6 100644 --- a/that_depends/providers/context_resources.py +++ b/that_depends/providers/context_resources.py @@ -2,7 +2,6 @@ import logging import typing import uuid -import warnings from contextlib import AbstractAsyncContextManager, AbstractContextManager from contextvars import ContextVar, Token from functools import wraps @@ -166,14 +165,3 @@ def _fetch_context(self) -> ResourceContext[T_co]: resource_context = ResourceContext(is_async=_is_container_context_async()) container_context.setdefault(self._internal_name, resource_context) return resource_context - - -class AsyncContextResource(ContextResource[T_co]): - def __init__( - self, - creator: typing.Callable[P, typing.AsyncIterator[T_co]], - *args: P.args, - **kwargs: P.kwargs, - ) -> None: - warnings.warn("AsyncContextResource is deprecated, use ContextResource instead", RuntimeWarning, stacklevel=1) - super().__init__(creator, *args, **kwargs) diff --git a/that_depends/providers/resources.py b/that_depends/providers/resources.py index 822386d..02f3aea 100644 --- a/that_depends/providers/resources.py +++ b/that_depends/providers/resources.py @@ -1,5 +1,4 @@ import typing -import warnings from that_depends.entities.resource_context import ResourceContext from that_depends.providers.base import AbstractResource, ResourceCreatorType @@ -33,14 +32,3 @@ def _fetch_context(self) -> ResourceContext[T_co]: async def tear_down(self) -> None: await self._fetch_context().tear_down() - - -class AsyncResource(Resource[T_co]): - def __init__( - self, - creator: typing.Callable[P, typing.AsyncIterator[T_co]], - *args: P.args, - **kwargs: P.kwargs, - ) -> None: - warnings.warn("AsyncResource is deprecated, use Resource instead", RuntimeWarning, stacklevel=1) - super().__init__(creator, *args, **kwargs)