@@ -8,7 +8,6 @@ import typing_extensions
8
8
from _collections_abc import dict_items , dict_keys , dict_values
9
9
from _typeshed import IdentityFunction , ReadableBuffer , SupportsKeysAndGetItem
10
10
from abc import ABCMeta , abstractmethod
11
- from contextlib import AbstractAsyncContextManager , AbstractContextManager
12
11
from re import Match as Match , Pattern as Pattern
13
12
from types import (
14
13
BuiltinFunctionType ,
@@ -24,10 +23,10 @@ from types import (
24
23
)
25
24
from typing_extensions import Never as _Never , ParamSpec as _ParamSpec
26
25
27
- if sys .version_info >= (3 , 10 ):
28
- from types import UnionType
29
26
if sys .version_info >= (3 , 9 ):
30
27
from types import GenericAlias
28
+ if sys .version_info >= (3 , 10 ):
29
+ from types import UnionType
31
30
32
31
__all__ = [
33
32
"AbstractSet" ,
@@ -428,17 +427,17 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return
428
427
@property
429
428
def gi_yieldfrom (self ) -> Generator [Any , Any , Any ] | None : ...
430
429
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
436
435
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 ]): ...
442
441
443
442
@runtime_checkable
444
443
class Awaitable (Protocol [_T_co ]):
0 commit comments