mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-03-03 19:25:48 +03:00
Remove code for EOL Python versions (#864)
This commit is contained in:
parent
f3b3b1baa4
commit
6e4794bab1
|
@ -1,17 +1,11 @@
|
||||||
"""Containers module."""
|
"""Containers module."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import copy as copy_module
|
import copy as copy_module
|
||||||
import json
|
import json
|
||||||
import sys
|
|
||||||
import importlib
|
import importlib
|
||||||
import inspect
|
import inspect
|
||||||
import warnings
|
|
||||||
|
|
||||||
try:
|
|
||||||
import asyncio
|
|
||||||
except ImportError:
|
|
||||||
asyncio = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -20,24 +14,7 @@ except ImportError:
|
||||||
|
|
||||||
from . import providers, errors
|
from . import providers, errors
|
||||||
from .providers cimport __is_future_or_coroutine
|
from .providers cimport __is_future_or_coroutine
|
||||||
|
from .wiring import wire, unwire
|
||||||
|
|
||||||
if sys.version_info[:2] >= (3, 6):
|
|
||||||
from .wiring import wire, unwire
|
|
||||||
else:
|
|
||||||
def wire(*args, **kwargs):
|
|
||||||
raise NotImplementedError("Wiring requires Python 3.6 or above")
|
|
||||||
|
|
||||||
def unwire(*args, **kwargs):
|
|
||||||
raise NotImplementedError("Wiring requires Python 3.6 or above")
|
|
||||||
|
|
||||||
if sys.version_info[:2] == (3, 5):
|
|
||||||
warnings.warn(
|
|
||||||
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
|
|
||||||
"This does not mean that there will be any immediate breaking changes, "
|
|
||||||
"but tests will no longer be executed on Python 3.5, and bugs will not be addressed.",
|
|
||||||
category=DeprecationWarning,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WiringConfiguration:
|
class WiringConfiguration:
|
||||||
|
@ -53,7 +30,7 @@ class WiringConfiguration:
|
||||||
return self.__class__(self.modules, self.packages, self.from_package, self.auto_wire)
|
return self.__class__(self.modules, self.packages, self.from_package, self.auto_wire)
|
||||||
|
|
||||||
|
|
||||||
class Container(object):
|
class Container:
|
||||||
"""Abstract container."""
|
"""Abstract container."""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
"""Providers module."""
|
"""Providers module."""
|
||||||
|
|
||||||
try:
|
import asyncio
|
||||||
import asyncio
|
|
||||||
except ImportError:
|
|
||||||
asyncio = None
|
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
cimport cython
|
cimport cython
|
||||||
|
@ -19,7 +15,7 @@ cdef tuple __COROUTINE_TYPES
|
||||||
|
|
||||||
|
|
||||||
# Base providers
|
# Base providers
|
||||||
cdef class Provider(object):
|
cdef class Provider:
|
||||||
cdef tuple _overridden
|
cdef tuple _overridden
|
||||||
cdef Provider _last_overriding
|
cdef Provider _last_overriding
|
||||||
cdef tuple _overrides
|
cdef tuple _overrides
|
||||||
|
@ -291,7 +287,7 @@ cdef class MethodCaller(Provider):
|
||||||
|
|
||||||
|
|
||||||
# Injections
|
# Injections
|
||||||
cdef class Injection(object):
|
cdef class Injection:
|
||||||
cdef object _value
|
cdef object _value
|
||||||
cdef int _is_provider
|
cdef int _is_provider
|
||||||
cdef int _is_delegated
|
cdef int _is_delegated
|
||||||
|
@ -313,12 +309,12 @@ cpdef tuple parse_named_injections(dict kwargs)
|
||||||
|
|
||||||
|
|
||||||
# Utils
|
# Utils
|
||||||
cdef class OverridingContext(object):
|
cdef class OverridingContext:
|
||||||
cdef Provider _overridden
|
cdef Provider _overridden
|
||||||
cdef Provider _overriding
|
cdef Provider _overriding
|
||||||
|
|
||||||
|
|
||||||
cdef class BaseSingletonResetContext(object):
|
cdef class BaseSingletonResetContext:
|
||||||
cdef object _singleton
|
cdef object _singleton
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import builtins
|
||||||
|
import contextvars
|
||||||
import copy
|
import copy
|
||||||
import errno
|
import errno
|
||||||
import functools
|
import functools
|
||||||
|
@ -13,21 +15,9 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import types
|
|
||||||
import warnings
|
import warnings
|
||||||
from configparser import ConfigParser as IniConfigParser
|
from configparser import ConfigParser as IniConfigParser
|
||||||
|
|
||||||
try:
|
|
||||||
import contextvars
|
|
||||||
except ImportError:
|
|
||||||
contextvars = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
import builtins
|
|
||||||
except ImportError:
|
|
||||||
# Python 2.7
|
|
||||||
import __builtin__ as builtins
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from inspect import _is_coroutine_mark as _is_coroutine_marker
|
from inspect import _is_coroutine_mark as _is_coroutine_marker
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -76,24 +66,6 @@ from .errors import (
|
||||||
cimport cython
|
cimport cython
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] == 3: # pragma: no cover
|
|
||||||
CLASS_TYPES = (type,)
|
|
||||||
else: # pragma: no cover
|
|
||||||
CLASS_TYPES = (type, types.ClassType)
|
|
||||||
|
|
||||||
copy._deepcopy_dispatch[types.MethodType] = \
|
|
||||||
lambda obj, memo: type(obj)(obj.im_func,
|
|
||||||
copy.deepcopy(obj.im_self, memo),
|
|
||||||
obj.im_class)
|
|
||||||
|
|
||||||
if sys.version_info[:2] == (3, 5):
|
|
||||||
warnings.warn(
|
|
||||||
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
|
|
||||||
"This does not mean that there will be any immediate breaking changes, "
|
|
||||||
"but tests will no longer be executed on Python 3.5, and bugs will not be addressed.",
|
|
||||||
category=DeprecationWarning,
|
|
||||||
)
|
|
||||||
|
|
||||||
config_env_marker_pattern = re.compile(
|
config_env_marker_pattern = re.compile(
|
||||||
r"\${(?P<name>[^}^{:]+)(?P<separator>:?)(?P<default>.*?)}",
|
r"\${(?P<name>[^}^{:]+)(?P<separator>:?)(?P<default>.*?)}",
|
||||||
)
|
)
|
||||||
|
@ -153,7 +125,7 @@ cdef int ASYNC_MODE_ENABLED = 1
|
||||||
cdef int ASYNC_MODE_DISABLED = 2
|
cdef int ASYNC_MODE_DISABLED = 2
|
||||||
|
|
||||||
cdef set __iscoroutine_typecache = set()
|
cdef set __iscoroutine_typecache = set()
|
||||||
cdef tuple __COROUTINE_TYPES = asyncio.coroutines._COROUTINE_TYPES if asyncio else tuple()
|
cdef tuple __COROUTINE_TYPES = asyncio.coroutines._COROUTINE_TYPES
|
||||||
|
|
||||||
cdef dict pydantic_settings_to_dict(settings, dict kwargs):
|
cdef dict pydantic_settings_to_dict(settings, dict kwargs):
|
||||||
if not has_pydantic_settings:
|
if not has_pydantic_settings:
|
||||||
|
@ -163,7 +135,7 @@ cdef dict pydantic_settings_to_dict(settings, dict kwargs):
|
||||||
f"\"pip install dependency-injector[{pydantic_extra}]\""
|
f"\"pip install dependency-injector[{pydantic_extra}]\""
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(settings, CLASS_TYPES) and issubclass(settings, PydanticSettings):
|
if isinstance(settings, type) and issubclass(settings, PydanticSettings):
|
||||||
raise Error(
|
raise Error(
|
||||||
"Got settings class, but expect instance: "
|
"Got settings class, but expect instance: "
|
||||||
"instead \"{0}\" use \"{0}()\"".format(settings.__name__)
|
"instead \"{0}\" use \"{0}()\"".format(settings.__name__)
|
||||||
|
@ -181,7 +153,7 @@ cdef dict pydantic_settings_to_dict(settings, dict kwargs):
|
||||||
return settings.model_dump(mode="python", **kwargs)
|
return settings.model_dump(mode="python", **kwargs)
|
||||||
|
|
||||||
|
|
||||||
cdef class Provider(object):
|
cdef class Provider:
|
||||||
"""Base provider class.
|
"""Base provider class.
|
||||||
|
|
||||||
:py:class:`Provider` is callable (implements ``__call__`` method). Every
|
:py:class:`Provider` is callable (implements ``__call__`` method). Every
|
||||||
|
@ -903,12 +875,9 @@ cdef class Dependency(Provider):
|
||||||
|
|
||||||
def set_instance_of(self, instance_of):
|
def set_instance_of(self, instance_of):
|
||||||
"""Set type."""
|
"""Set type."""
|
||||||
if not isinstance(instance_of, CLASS_TYPES):
|
if not isinstance(instance_of, type):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"\"instance_of\" has incorrect type (expected {0}, got {1}))".format(
|
f"\"instance_of\" is not a class (got {instance_of!r}))",
|
||||||
CLASS_TYPES,
|
|
||||||
instance_of,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
self._instance_of = instance_of
|
self._instance_of = instance_of
|
||||||
return self
|
return self
|
||||||
|
@ -1470,8 +1439,6 @@ cdef class Coroutine(Callable):
|
||||||
|
|
||||||
def set_provides(self, provides):
|
def set_provides(self, provides):
|
||||||
"""Set provider provides."""
|
"""Set provider provides."""
|
||||||
if not asyncio:
|
|
||||||
raise Error("Package asyncio is not available")
|
|
||||||
provides = _resolve_string_import(provides)
|
provides = _resolve_string_import(provides)
|
||||||
if provides and not asyncio.iscoroutinefunction(provides):
|
if provides and not asyncio.iscoroutinefunction(provides):
|
||||||
raise Error(f"Provider {_class_qualname(self)} expected to get coroutine function, "
|
raise Error(f"Provider {_class_qualname(self)} expected to get coroutine function, "
|
||||||
|
@ -3970,18 +3937,14 @@ cdef class Resource(Provider):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_resource_subclass(instance):
|
def _is_resource_subclass(instance):
|
||||||
if sys.version_info < (3, 5):
|
if not isinstance(instance, type):
|
||||||
return False
|
|
||||||
if not isinstance(instance, CLASS_TYPES):
|
|
||||||
return
|
return
|
||||||
from . import resources
|
from . import resources
|
||||||
return issubclass(instance, resources.Resource)
|
return issubclass(instance, resources.Resource)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_async_resource_subclass(instance):
|
def _is_async_resource_subclass(instance):
|
||||||
if sys.version_info < (3, 5):
|
if not isinstance(instance, type):
|
||||||
return False
|
|
||||||
if not isinstance(instance, CLASS_TYPES):
|
|
||||||
return
|
return
|
||||||
from . import resources
|
from . import resources
|
||||||
return issubclass(instance, resources.AsyncResource)
|
return issubclass(instance, resources.AsyncResource)
|
||||||
|
@ -4639,7 +4602,7 @@ cdef class MethodCaller(Provider):
|
||||||
future_result.set_result(result)
|
future_result.set_result(result)
|
||||||
|
|
||||||
|
|
||||||
cdef class Injection(object):
|
cdef class Injection:
|
||||||
"""Abstract injection class."""
|
"""Abstract injection class."""
|
||||||
|
|
||||||
|
|
||||||
|
@ -4766,7 +4729,7 @@ cpdef tuple parse_named_injections(dict kwargs):
|
||||||
return tuple(injections)
|
return tuple(injections)
|
||||||
|
|
||||||
|
|
||||||
cdef class OverridingContext(object):
|
cdef class OverridingContext:
|
||||||
"""Provider overriding context.
|
"""Provider overriding context.
|
||||||
|
|
||||||
:py:class:`OverridingContext` is used by :py:meth:`Provider.override` for
|
:py:class:`OverridingContext` is used by :py:meth:`Provider.override` for
|
||||||
|
@ -4802,7 +4765,7 @@ cdef class OverridingContext(object):
|
||||||
self._overridden.reset_last_overriding()
|
self._overridden.reset_last_overriding()
|
||||||
|
|
||||||
|
|
||||||
cdef class BaseSingletonResetContext(object):
|
cdef class BaseSingletonResetContext:
|
||||||
|
|
||||||
def __init__(self, Provider provider):
|
def __init__(self, Provider provider):
|
||||||
self._singleton = provider
|
self._singleton = provider
|
||||||
|
@ -4838,7 +4801,7 @@ cpdef bint is_provider(object instance):
|
||||||
|
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return (not isinstance(instance, CLASS_TYPES) and
|
return (not isinstance(instance, type) and
|
||||||
getattr(instance, "__IS_PROVIDER__", False) is True)
|
getattr(instance, "__IS_PROVIDER__", False) is True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4866,7 +4829,7 @@ cpdef bint is_delegated(object instance):
|
||||||
|
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return (not isinstance(instance, CLASS_TYPES) and
|
return (not isinstance(instance, type) and
|
||||||
getattr(instance, "__IS_DELEGATED__", False) is True)
|
getattr(instance, "__IS_DELEGATED__", False) is True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4897,7 +4860,7 @@ cpdef bint is_container_instance(object instance):
|
||||||
|
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return (not isinstance(instance, CLASS_TYPES) and
|
return (not isinstance(instance, type) and
|
||||||
getattr(instance, "__IS_CONTAINER__", False) is True)
|
getattr(instance, "__IS_CONTAINER__", False) is True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4909,7 +4872,7 @@ cpdef bint is_container_class(object instance):
|
||||||
|
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return (isinstance(instance, CLASS_TYPES) and
|
return (isinstance(instance, type) and
|
||||||
getattr(instance, "__IS_CONTAINER__", False) is True)
|
getattr(instance, "__IS_CONTAINER__", False) is True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import importlib.machinery
|
||||||
import inspect
|
import inspect
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
@ -24,12 +23,6 @@ from typing import (
|
||||||
cast,
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
if sys.version_info < (3, 7):
|
|
||||||
from typing import GenericMeta
|
|
||||||
else:
|
|
||||||
|
|
||||||
class GenericMeta(type): ...
|
|
||||||
|
|
||||||
|
|
||||||
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
|
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
|
||||||
if sys.version_info >= (3, 9):
|
if sys.version_info >= (3, 9):
|
||||||
|
@ -73,13 +66,6 @@ except ImportError:
|
||||||
|
|
||||||
from . import providers
|
from . import providers
|
||||||
|
|
||||||
if sys.version_info[:2] == (3, 5):
|
|
||||||
warnings.warn(
|
|
||||||
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
|
|
||||||
"This does not mean that there will be any immediate breaking changes, "
|
|
||||||
"but tests will no longer be executed on Python 3.5, and bugs will not be addressed.",
|
|
||||||
category=DeprecationWarning,
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
"wire",
|
"wire",
|
||||||
|
@ -888,15 +874,7 @@ def provided() -> ProvidedInstance:
|
||||||
return ProvidedInstance()
|
return ProvidedInstance()
|
||||||
|
|
||||||
|
|
||||||
class ClassGetItemMeta(GenericMeta):
|
class _Marker(Generic[T]):
|
||||||
def __getitem__(cls, item):
|
|
||||||
# Spike for Python 3.6
|
|
||||||
if isinstance(item, tuple):
|
|
||||||
return cls(*item)
|
|
||||||
return cls(item)
|
|
||||||
|
|
||||||
|
|
||||||
class _Marker(Generic[T], metaclass=ClassGetItemMeta):
|
|
||||||
|
|
||||||
__IS_MARKER__ = True
|
__IS_MARKER__ = True
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
[pytest]
|
|
||||||
testpaths = tests/unit/
|
|
||||||
python_files = test_*_py2_py3.py
|
|
||||||
asyncio_mode = auto
|
|
||||||
filterwarnings =
|
|
||||||
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
|
||||||
ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\.0\.0:DeprecationWarning
|
|
||||||
ignore:Please use \`.*?\` from the \`scipy.*?\`(.*?)namespace is deprecated\.:DeprecationWarning
|
|
||||||
ignore:The \`scipy(.*?)\` namespace is deprecated(.*):DeprecationWarning
|
|
||||||
ignore:ssl\.PROTOCOL_TLS is deprecated:DeprecationWarning:botocore.*
|
|
|
@ -1,10 +0,0 @@
|
||||||
[pytest]
|
|
||||||
testpaths = tests/unit/
|
|
||||||
python_files = test_*_py3.py
|
|
||||||
asyncio_mode = auto
|
|
||||||
filterwarnings =
|
|
||||||
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
|
||||||
ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\.0\.0:DeprecationWarning
|
|
||||||
ignore:Please use \`.*?\` from the \`scipy.*?\`(.*?)namespace is deprecated\.:DeprecationWarning
|
|
||||||
ignore:The \`scipy(.*?)\` namespace is deprecated(.*):DeprecationWarning
|
|
||||||
ignore:ssl\.PROTOCOL_TLS is deprecated:DeprecationWarning:botocore.*
|
|
Loading…
Reference in New Issue
Block a user