3
3
from __future__ import absolute_import
4
4
5
5
import asyncio
6
+ import builtins
7
+ import contextvars
6
8
import copy
7
9
import errno
8
10
import functools
@@ -13,21 +15,9 @@ import os
13
15
import re
14
16
import sys
15
17
import threading
16
- import types
17
18
import warnings
18
19
from configparser import ConfigParser as IniConfigParser
19
20
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
-
31
21
try :
32
22
from inspect import _is_coroutine_mark as _is_coroutine_marker
33
23
except ImportError :
@@ -76,24 +66,6 @@ from .errors import (
76
66
cimport cython
77
67
78
68
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
-
97
69
config_env_marker_pattern = re.compile(
98
70
r " \$ {( ?P<name> [^ }^{: ]+ ) ( ?P<separator> :? ) ( ?P<default> . *? ) }" ,
99
71
)
@@ -153,7 +125,7 @@ cdef int ASYNC_MODE_ENABLED = 1
153
125
cdef int ASYNC_MODE_DISABLED = 2
154
126
155
127
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
157
129
158
130
cdef dict pydantic_settings_to_dict(settings, dict kwargs):
159
131
if not has_pydantic_settings:
@@ -163,7 +135,7 @@ cdef dict pydantic_settings_to_dict(settings, dict kwargs):
163
135
f" \" pip install dependency-injector[{pydantic_extra}]\" "
164
136
)
165
137
166
- if isinstance (settings, CLASS_TYPES ) and issubclass (settings, PydanticSettings):
138
+ if isinstance (settings, type ) and issubclass (settings, PydanticSettings):
167
139
raise Error(
168
140
" Got settings class, but expect instance: "
169
141
" instead \" {0}\" use \" {0}()\" " .format(settings.__name__ )
@@ -181,7 +153,7 @@ cdef dict pydantic_settings_to_dict(settings, dict kwargs):
181
153
return settings.model_dump(mode = " python" , ** kwargs)
182
154
183
155
184
- cdef class Provider( object ) :
156
+ cdef class Provider:
185
157
""" Base provider class.
186
158
187
159
:py:class:`Provider` is callable (implements ``__call__`` method). Every
@@ -903,12 +875,9 @@ cdef class Dependency(Provider):
903
875
904
876
def set_instance_of (self , instance_of ):
905
877
""" Set type."""
906
- if not isinstance (instance_of, CLASS_TYPES ):
878
+ if not isinstance (instance_of, type ):
907
879
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}))" ,
912
881
)
913
882
self ._instance_of = instance_of
914
883
return self
@@ -1470,8 +1439,6 @@ cdef class Coroutine(Callable):
1470
1439
1471
1440
def set_provides (self , provides ):
1472
1441
""" Set provider provides."""
1473
- if not asyncio:
1474
- raise Error(" Package asyncio is not available" )
1475
1442
provides = _resolve_string_import(provides)
1476
1443
if provides and not asyncio.iscoroutinefunction(provides):
1477
1444
raise Error(f" Provider {_class_qualname(self)} expected to get coroutine function, "
@@ -3970,18 +3937,14 @@ cdef class Resource(Provider):
3970
3937
3971
3938
@staticmethod
3972
3939
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 ):
3976
3941
return
3977
3942
from . import resources
3978
3943
return issubclass (instance, resources.Resource)
3979
3944
3980
3945
@staticmethod
3981
3946
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 ):
3985
3948
return
3986
3949
from . import resources
3987
3950
return issubclass (instance, resources.AsyncResource)
@@ -4639,7 +4602,7 @@ cdef class MethodCaller(Provider):
4639
4602
future_result.set_result(result)
4640
4603
4641
4604
4642
- cdef class Injection( object ) :
4605
+ cdef class Injection:
4643
4606
""" Abstract injection class."""
4644
4607
4645
4608
@@ -4766,7 +4729,7 @@ cpdef tuple parse_named_injections(dict kwargs):
4766
4729
return tuple (injections)
4767
4730
4768
4731
4769
- cdef class OverridingContext( object ) :
4732
+ cdef class OverridingContext:
4770
4733
""" Provider overriding context.
4771
4734
4772
4735
:py:class:`OverridingContext` is used by :py:meth:`Provider.override` for
@@ -4802,7 +4765,7 @@ cdef class OverridingContext(object):
4802
4765
self ._overridden.reset_last_overriding()
4803
4766
4804
4767
4805
- cdef class BaseSingletonResetContext( object ) :
4768
+ cdef class BaseSingletonResetContext:
4806
4769
4807
4770
def __init__ (self , Provider provider ):
4808
4771
self ._singleton = provider
@@ -4838,7 +4801,7 @@ cpdef bint is_provider(object instance):
4838
4801
4839
4802
:rtype: bool
4840
4803
"""
4841
- return (not isinstance (instance, CLASS_TYPES ) and
4804
+ return (not isinstance (instance, type ) and
4842
4805
getattr (instance, " __IS_PROVIDER__" , False ) is True )
4843
4806
4844
4807
@@ -4866,7 +4829,7 @@ cpdef bint is_delegated(object instance):
4866
4829
4867
4830
:rtype: bool
4868
4831
"""
4869
- return (not isinstance (instance, CLASS_TYPES ) and
4832
+ return (not isinstance (instance, type ) and
4870
4833
getattr (instance, " __IS_DELEGATED__" , False ) is True )
4871
4834
4872
4835
@@ -4897,7 +4860,7 @@ cpdef bint is_container_instance(object instance):
4897
4860
4898
4861
:rtype: bool
4899
4862
"""
4900
- return (not isinstance (instance, CLASS_TYPES ) and
4863
+ return (not isinstance (instance, type ) and
4901
4864
getattr (instance, " __IS_CONTAINER__" , False ) is True )
4902
4865
4903
4866
@@ -4909,7 +4872,7 @@ cpdef bint is_container_class(object instance):
4909
4872
4910
4873
:rtype: bool
4911
4874
"""
4912
- return (isinstance (instance, CLASS_TYPES ) and
4875
+ return (isinstance (instance, type ) and
4913
4876
getattr (instance, " __IS_CONTAINER__" , False ) is True )
4914
4877
4915
4878
0 commit comments