33from __future__ import absolute_import
44
55import asyncio
6+ import builtins
7+ import contextvars
68import copy
79import errno
810import functools
@@ -13,21 +15,9 @@ import os
1315import re
1416import sys
1517import threading
16- import types
1718import warnings
1819from 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-
3121try :
3222 from inspect import _is_coroutine_mark as _is_coroutine_marker
3323except ImportError :
@@ -76,24 +66,6 @@ from .errors import (
7666cimport 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-
9769config_env_marker_pattern = re.compile(
9870 r " \$ {( ?P<name> [^ }^{: ]+ ) ( ?P<separator> :? ) ( ?P<default> . *? ) }" ,
9971)
@@ -153,7 +125,7 @@ cdef int ASYNC_MODE_ENABLED = 1
153125cdef int ASYNC_MODE_DISABLED = 2
154126
155127cdef 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
158130cdef 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
0 commit comments