Skip to content

Commit 57123ce

Browse files
committed
Merge branch 'master' into develop
2 parents 9b66d4b + 6e4794b commit 57123ce

File tree

6 files changed

+25
-131
lines changed

6 files changed

+25
-131
lines changed

src/dependency_injector/containers.pyx

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
"""Containers module."""
22

3+
import asyncio
34
import contextlib
45
import copy as copy_module
56
import json
6-
import sys
77
import importlib
88
import inspect
9-
import warnings
10-
11-
try:
12-
import asyncio
13-
except ImportError:
14-
asyncio = None
159

1610
try:
1711
import yaml
@@ -20,24 +14,7 @@ except ImportError:
2014

2115
from . import providers, errors
2216
from .providers cimport __is_future_or_coroutine
23-
24-
25-
if sys.version_info[:2] >= (3, 6):
26-
from .wiring import wire, unwire
27-
else:
28-
def wire(*args, **kwargs):
29-
raise NotImplementedError("Wiring requires Python 3.6 or above")
30-
31-
def unwire(*args, **kwargs):
32-
raise NotImplementedError("Wiring requires Python 3.6 or above")
33-
34-
if sys.version_info[:2] == (3, 5):
35-
warnings.warn(
36-
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
37-
"This does not mean that there will be any immediate breaking changes, "
38-
"but tests will no longer be executed on Python 3.5, and bugs will not be addressed.",
39-
category=DeprecationWarning,
40-
)
17+
from .wiring import wire, unwire
4118

4219

4320
class WiringConfiguration:
@@ -53,7 +30,7 @@ class WiringConfiguration:
5330
return self.__class__(self.modules, self.packages, self.from_package, self.auto_wire)
5431

5532

56-
class Container(object):
33+
class Container:
5734
"""Abstract container."""
5835

5936

src/dependency_injector/providers.pxd

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
"""Providers module."""
22

3-
try:
4-
import asyncio
5-
except ImportError:
6-
asyncio = None
7-
3+
import asyncio
84
import functools
95

106
cimport cython
@@ -19,7 +15,7 @@ cdef tuple __COROUTINE_TYPES
1915

2016

2117
# Base providers
22-
cdef class Provider(object):
18+
cdef class Provider:
2319
cdef tuple _overridden
2420
cdef Provider _last_overriding
2521
cdef tuple _overrides
@@ -291,7 +287,7 @@ cdef class MethodCaller(Provider):
291287

292288

293289
# Injections
294-
cdef class Injection(object):
290+
cdef class Injection:
295291
cdef object _value
296292
cdef int _is_provider
297293
cdef int _is_delegated
@@ -313,12 +309,12 @@ cpdef tuple parse_named_injections(dict kwargs)
313309

314310

315311
# Utils
316-
cdef class OverridingContext(object):
312+
cdef class OverridingContext:
317313
cdef Provider _overridden
318314
cdef Provider _overriding
319315

320316

321-
cdef class BaseSingletonResetContext(object):
317+
cdef class BaseSingletonResetContext:
322318
cdef object _singleton
323319

324320

src/dependency_injector/providers.pyx

+16-53
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from __future__ import absolute_import
44

55
import asyncio
6+
import builtins
7+
import contextvars
68
import copy
79
import errno
810
import functools
@@ -13,21 +15,9 @@ import os
1315
import re
1416
import sys
1517
import threading
16-
import types
1718
import warnings
1819
from configparser import ConfigParser as IniConfigParser
1920

20-
try:
21-
import contextvars
22-
except ImportError:
23-
contextvars = None
24-
25-
try:
26-
import builtins
27-
except ImportError:
28-
# Python 2.7
29-
import __builtin__ as builtins
30-
3121
try:
3222
from inspect import _is_coroutine_mark as _is_coroutine_marker
3323
except ImportError:
@@ -76,24 +66,6 @@ from .errors import (
7666
cimport cython
7767

7868

79-
if sys.version_info[0] == 3: # pragma: no cover
80-
CLASS_TYPES = (type,)
81-
else: # pragma: no cover
82-
CLASS_TYPES = (type, types.ClassType)
83-
84-
copy._deepcopy_dispatch[types.MethodType] = \
85-
lambda obj, memo: type(obj)(obj.im_func,
86-
copy.deepcopy(obj.im_self, memo),
87-
obj.im_class)
88-
89-
if sys.version_info[:2] == (3, 5):
90-
warnings.warn(
91-
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
92-
"This does not mean that there will be any immediate breaking changes, "
93-
"but tests will no longer be executed on Python 3.5, and bugs will not be addressed.",
94-
category=DeprecationWarning,
95-
)
96-
9769
config_env_marker_pattern = re.compile(
9870
r"\${(?P<name>[^}^{:]+)(?P<separator>:?)(?P<default>.*?)}",
9971
)
@@ -153,7 +125,7 @@ cdef int ASYNC_MODE_ENABLED = 1
153125
cdef int ASYNC_MODE_DISABLED = 2
154126

155127
cdef set __iscoroutine_typecache = set()
156-
cdef tuple __COROUTINE_TYPES = asyncio.coroutines._COROUTINE_TYPES if asyncio else tuple()
128+
cdef tuple __COROUTINE_TYPES = asyncio.coroutines._COROUTINE_TYPES
157129

158130
cdef dict pydantic_settings_to_dict(settings, dict kwargs):
159131
if not has_pydantic_settings:
@@ -163,7 +135,7 @@ cdef dict pydantic_settings_to_dict(settings, dict kwargs):
163135
f"\"pip install dependency-injector[{pydantic_extra}]\""
164136
)
165137

166-
if isinstance(settings, CLASS_TYPES) and issubclass(settings, PydanticSettings):
138+
if isinstance(settings, type) and issubclass(settings, PydanticSettings):
167139
raise Error(
168140
"Got settings class, but expect instance: "
169141
"instead \"{0}\" use \"{0}()\"".format(settings.__name__)
@@ -181,7 +153,7 @@ cdef dict pydantic_settings_to_dict(settings, dict kwargs):
181153
return settings.model_dump(mode="python", **kwargs)
182154

183155

184-
cdef class Provider(object):
156+
cdef class Provider:
185157
"""Base provider class.
186158
187159
:py:class:`Provider` is callable (implements ``__call__`` method). Every
@@ -903,12 +875,9 @@ cdef class Dependency(Provider):
903875

904876
def set_instance_of(self, instance_of):
905877
"""Set type."""
906-
if not isinstance(instance_of, CLASS_TYPES):
878+
if not isinstance(instance_of, type):
907879
raise TypeError(
908-
"\"instance_of\" has incorrect type (expected {0}, got {1}))".format(
909-
CLASS_TYPES,
910-
instance_of,
911-
),
880+
f"\"instance_of\" is not a class (got {instance_of!r}))",
912881
)
913882
self._instance_of = instance_of
914883
return self
@@ -1470,8 +1439,6 @@ cdef class Coroutine(Callable):
14701439

14711440
def set_provides(self, provides):
14721441
"""Set provider provides."""
1473-
if not asyncio:
1474-
raise Error("Package asyncio is not available")
14751442
provides = _resolve_string_import(provides)
14761443
if provides and not asyncio.iscoroutinefunction(provides):
14771444
raise Error(f"Provider {_class_qualname(self)} expected to get coroutine function, "
@@ -3970,18 +3937,14 @@ cdef class Resource(Provider):
39703937

39713938
@staticmethod
39723939
def _is_resource_subclass(instance):
3973-
if sys.version_info < (3, 5):
3974-
return False
3975-
if not isinstance(instance, CLASS_TYPES):
3940+
if not isinstance(instance, type):
39763941
return
39773942
from . import resources
39783943
return issubclass(instance, resources.Resource)
39793944

39803945
@staticmethod
39813946
def _is_async_resource_subclass(instance):
3982-
if sys.version_info < (3, 5):
3983-
return False
3984-
if not isinstance(instance, CLASS_TYPES):
3947+
if not isinstance(instance, type):
39853948
return
39863949
from . import resources
39873950
return issubclass(instance, resources.AsyncResource)
@@ -4639,7 +4602,7 @@ cdef class MethodCaller(Provider):
46394602
future_result.set_result(result)
46404603

46414604

4642-
cdef class Injection(object):
4605+
cdef class Injection:
46434606
"""Abstract injection class."""
46444607

46454608

@@ -4766,7 +4729,7 @@ cpdef tuple parse_named_injections(dict kwargs):
47664729
return tuple(injections)
47674730

47684731

4769-
cdef class OverridingContext(object):
4732+
cdef class OverridingContext:
47704733
"""Provider overriding context.
47714734
47724735
:py:class:`OverridingContext` is used by :py:meth:`Provider.override` for
@@ -4802,7 +4765,7 @@ cdef class OverridingContext(object):
48024765
self._overridden.reset_last_overriding()
48034766

48044767

4805-
cdef class BaseSingletonResetContext(object):
4768+
cdef class BaseSingletonResetContext:
48064769

48074770
def __init__(self, Provider provider):
48084771
self._singleton = provider
@@ -4838,7 +4801,7 @@ cpdef bint is_provider(object instance):
48384801
48394802
:rtype: bool
48404803
"""
4841-
return (not isinstance(instance, CLASS_TYPES) and
4804+
return (not isinstance(instance, type) and
48424805
getattr(instance, "__IS_PROVIDER__", False) is True)
48434806

48444807

@@ -4866,7 +4829,7 @@ cpdef bint is_delegated(object instance):
48664829
48674830
:rtype: bool
48684831
"""
4869-
return (not isinstance(instance, CLASS_TYPES) and
4832+
return (not isinstance(instance, type) and
48704833
getattr(instance, "__IS_DELEGATED__", False) is True)
48714834

48724835

@@ -4897,7 +4860,7 @@ cpdef bint is_container_instance(object instance):
48974860
48984861
:rtype: bool
48994862
"""
4900-
return (not isinstance(instance, CLASS_TYPES) and
4863+
return (not isinstance(instance, type) and
49014864
getattr(instance, "__IS_CONTAINER__", False) is True)
49024865

49034866

@@ -4909,7 +4872,7 @@ cpdef bint is_container_class(object instance):
49094872
49104873
:rtype: bool
49114874
"""
4912-
return (isinstance(instance, CLASS_TYPES) and
4875+
return (isinstance(instance, type) and
49134876
getattr(instance, "__IS_CONTAINER__", False) is True)
49144877

49154878

src/dependency_injector/wiring.py

+1-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import inspect
77
import pkgutil
88
import sys
9-
import warnings
109
from types import ModuleType
1110
from typing import (
1211
Any,
@@ -24,12 +23,6 @@
2423
cast,
2524
)
2625

27-
if sys.version_info < (3, 7):
28-
from typing import GenericMeta
29-
else:
30-
31-
class GenericMeta(type): ...
32-
3326

3427
# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
3528
if sys.version_info >= (3, 9):
@@ -73,13 +66,6 @@ def get_origin(tp):
7366

7467
from . import providers
7568

76-
if sys.version_info[:2] == (3, 5):
77-
warnings.warn(
78-
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
79-
"This does not mean that there will be any immediate breaking changes, "
80-
"but tests will no longer be executed on Python 3.5, and bugs will not be addressed.",
81-
category=DeprecationWarning,
82-
)
8369

8470
__all__ = (
8571
"wire",
@@ -888,15 +874,7 @@ def provided() -> ProvidedInstance:
888874
return ProvidedInstance()
889875

890876

891-
class ClassGetItemMeta(GenericMeta):
892-
def __getitem__(cls, item):
893-
# Spike for Python 3.6
894-
if isinstance(item, tuple):
895-
return cls(*item)
896-
return cls(item)
897-
898-
899-
class _Marker(Generic[T], metaclass=ClassGetItemMeta):
877+
class _Marker(Generic[T]):
900878

901879
__IS_MARKER__ = True
902880

tests/.configs/pytest-py27.ini

-10
This file was deleted.

tests/.configs/pytest-py35.ini

-10
This file was deleted.

0 commit comments

Comments
 (0)