@@ -8,7 +8,6 @@ import typing_extensions
88from _collections_abc import dict_items , dict_keys , dict_values
99from _typeshed import IdentityFunction , ReadableBuffer , SupportsKeysAndGetItem
1010from abc import ABCMeta , abstractmethod
11- from contextlib import AbstractAsyncContextManager , AbstractContextManager
1211from re import Match as Match , Pattern as Pattern
1312from types import (
1413 BuiltinFunctionType ,
@@ -24,10 +23,10 @@ from types import (
2423)
2524from typing_extensions import Never as _Never , ParamSpec as _ParamSpec
2625
27- if sys .version_info >= (3 , 10 ):
28- from types import UnionType
2926if sys .version_info >= (3 , 9 ):
3027 from types import GenericAlias
28+ if sys .version_info >= (3 , 10 ):
29+ from types import UnionType
3130
3231__all__ = [
3332 "AbstractSet" ,
@@ -428,17 +427,17 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return
428427 @property
429428 def gi_yieldfrom (self ) -> Generator [Any , Any , Any ] | None : ...
430429
431- # NOTE: Technically we would like this to be able to accept a second parameter as well, just
432- # like it's counterpart in contextlib, however `typing._SpecialGenericAlias` enforces the
433- # correct number of arguments at runtime, so we would be hiding runtime errors.
434- @ runtime_checkable
435- class ContextManager ( AbstractContextManager [ _T_co , bool | None ], Protocol [ _T_co ]): ...
430+ # NOTE: Prior to Python 3.13 these aliases are lacking the second _ExitT_co parameter
431+ if sys . version_info >= ( 3 , 13 ):
432+ from contextlib import AbstractAsyncContextManager as AsyncContextManager , AbstractContextManager as ContextManager
433+ else :
434+ from contextlib import AbstractAsyncContextManager , AbstractContextManager
436435
437- # NOTE: Technically we would like this to be able to accept a second parameter as well, just
438- # like it's counterpart in contextlib, however `typing._SpecialGenericAlias` enforces the
439- # correct number of arguments at runtime, so we would be hiding runtime errors.
440- @runtime_checkable
441- class AsyncContextManager (AbstractAsyncContextManager [_T_co , bool | None ], Protocol [_T_co ]): ...
436+ @ runtime_checkable
437+ class ContextManager ( AbstractContextManager [ _T_co , bool | None ], Protocol [ _T_co ]): ...
438+
439+ @runtime_checkable
440+ class AsyncContextManager (AbstractAsyncContextManager [_T_co , bool | None ], Protocol [_T_co ]): ...
442441
443442@runtime_checkable
444443class Awaitable (Protocol [_T_co ]):
0 commit comments