4545 overload ,
4646)
4747
48- try :
49- from typing import NoReturn
50- except ImportError :
51- from typing_extensions import NoReturn
52-
53- # This is a messy, type-wise, because we not only have two potentially conflicting imports here
54- # The easiest way to make mypy happy here is to tell it the versions from typing_extensions are
55- # canonical. Since this typing_extensions import is only for mypy it'll work even without
56- # typing_extensions actually installed so all's good.
57- if TYPE_CHECKING :
58- from typing_extensions import Annotated , _AnnotatedAlias , get_type_hints
59- else :
60- # Ignoring errors here as typing_extensions stub doesn't know about those things yet
61- try :
62- from typing import Annotated , _AnnotatedAlias , get_type_hints
63- except ImportError :
64- from typing_extensions import Annotated , _AnnotatedAlias , get_type_hints
48+ from typing import Annotated , NoReturn , _AnnotatedAlias , get_type_hints
6549
6650
6751__author__ = 'Alec Thomas <alec@swapoff.org>'
@@ -108,7 +92,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
10892InjectT = TypeVar ('InjectT' )
10993Inject = Annotated [InjectT , _inject_marker ]
11094"""An experimental way to declare injectable dependencies utilizing a `PEP 593`_ implementation
111- in Python 3.9 and backported to Python 3.7+ in `typing_extensions` .
95+ in Python 3.9.
11296
11397Those two declarations are equivalent::
11498
@@ -136,19 +120,18 @@ def fun(t: Inject[SomeType], s: SomeOtherType) -> None:
136120 A way to inspect how various injection declarations interact with each other.
137121
138122.. versionadded:: 0.18.0
139- .. note:: Requires Python 3.7 +.
123+ .. note:: Requires Python 3.9 +.
140124.. note::
141125
142126 If you're using mypy you need the version 0.750 or newer to fully type-check code using this
143127 construct.
144128
145129.. _PEP 593: https://www.python.org/dev/peps/pep-0593/
146- .. _typing_extensions: https://pypi.org/project/typing-extensions/
147130"""
148131
149132NoInject = Annotated [InjectT , _noinject_marker ]
150133"""An experimental way to declare noninjectable dependencies utilizing a `PEP 593`_ implementation
151- in Python 3.9 and backported to Python 3.7+ in `typing_extensions` .
134+ in Python 3.9.
152135
153136Since :func:`inject` declares all function's parameters to be injectable there needs to be a way
154137to opt out of it. This has been provided by :func:`noninjectable` but `noninjectable` suffers from
@@ -175,14 +158,13 @@ def fun(a: TypeA, b: NoInject[TypeB]) -> None:
175158 A way to inspect how various injection declarations interact with each other.
176159
177160.. versionadded:: 0.18.0
178- .. note:: Requires Python 3.7 +.
161+ .. note:: Requires Python 3.9 +.
179162.. note::
180163
181164 If you're using mypy you need the version 0.750 or newer to fully type-check code using this
182165 construct.
183166
184167.. _PEP 593: https://www.python.org/dev/peps/pep-0593/
185- .. _typing_extensions: https://pypi.org/project/typing-extensions/
186168"""
187169
188170
@@ -791,13 +773,7 @@ def _ensure_iterable(item_or_list: Union[T, List[T]]) -> List[T]:
791773
792774
793775def _punch_through_alias (type_ : Any ) -> type :
794- if (
795- sys .version_info < (3 , 10 )
796- and getattr (type_ , '__qualname__' , '' ) == 'NewType.<locals>.new_type'
797- or sys .version_info >= (3 , 10 )
798- and type (type_ ).__module__ == 'typing'
799- and type (type_ ).__name__ == 'NewType'
800- ):
776+ if type (type_ ).__module__ == 'typing' and type (type_ ).__name__ == 'NewType' :
801777 return type_ .__supertype__
802778 elif isinstance (type_ , _AnnotatedAlias ) and getattr (type_ , '__metadata__' , None ) is not None :
803779 return type_ .__origin__
0 commit comments