1
1
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
2
2
import sys
3
- from _typeshed import IdentityFunction , Incomplete , ReadableBuffer , Self as TypeshedSelf , SupportsKeysAndGetItem
3
+ from _typeshed import IdentityFunction , Incomplete , Self as TypeshedSelf , SupportsKeysAndGetItem
4
4
from abc import ABCMeta , abstractmethod
5
+ from contextlib import AbstractAsyncContextManager , AbstractContextManager
6
+ from re import Match as Match , Pattern as Pattern
5
7
from types import (
6
8
BuiltinFunctionType ,
7
9
CodeType ,
@@ -14,10 +16,7 @@ from types import (
14
16
TracebackType ,
15
17
WrapperDescriptorType ,
16
18
)
17
- from typing_extensions import Literal as _Literal , ParamSpec as _ParamSpec , final as _final
18
-
19
- if sys .version_info >= (3 , 9 ):
20
- from types import GenericAlias
19
+ from typing_extensions import ParamSpec as _ParamSpec , final as _final
21
20
22
21
__all__ = [
23
22
"AbstractSet" ,
@@ -120,6 +119,9 @@ if sys.version_info >= (3, 11):
120
119
"reveal_type" ,
121
120
]
122
121
122
+ ContextManager = AbstractContextManager
123
+ AsyncContextManager = AbstractAsyncContextManager
124
+
123
125
# This itself is only available during type checking
124
126
def type_check_only (func_or_cls : _F ) -> _F : ...
125
127
@@ -568,22 +570,6 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
568
570
if sys .version_info >= (3 , 8 ):
569
571
def __reversed__ (self ) -> Iterator [_VT_co ]: ...
570
572
571
- @runtime_checkable
572
- class ContextManager (Protocol [_T_co ]):
573
- def __enter__ (self ) -> _T_co : ...
574
- @abstractmethod
575
- def __exit__ (
576
- self , __exc_type : Type [BaseException ] | None , __exc_value : BaseException | None , __traceback : TracebackType | None
577
- ) -> bool | None : ...
578
-
579
- @runtime_checkable
580
- class AsyncContextManager (Protocol [_T_co ]):
581
- async def __aenter__ (self ) -> _T_co : ...
582
- @abstractmethod
583
- async def __aexit__ (
584
- self , __exc_type : Type [BaseException ] | None , __exc_value : BaseException | None , __traceback : TracebackType | None
585
- ) -> bool | None : ...
586
-
587
573
class Mapping (Collection [_KT ], Generic [_KT , _VT_co ]):
588
574
# TODO: We wish the key type could also be covariant, but that doesn't work,
589
575
# see discussion in https://github.com/python/typing/pull/273.
@@ -718,119 +704,6 @@ class TextIO(IO[str]):
718
704
719
705
class ByteString (Sequence [int ], metaclass = ABCMeta ): ...
720
706
721
- @_final
722
- class Match (Generic [AnyStr ]):
723
- @property
724
- def pos (self ) -> int : ...
725
- @property
726
- def endpos (self ) -> int : ...
727
- @property
728
- def lastindex (self ) -> int | None : ...
729
- @property
730
- def lastgroup (self ) -> str | None : ...
731
- @property
732
- def string (self ) -> AnyStr : ...
733
-
734
- # The regular expression object whose match() or search() method produced
735
- # this match instance.
736
- @property
737
- def re (self ) -> Pattern [AnyStr ]: ...
738
- @overload
739
- def expand (self : Match [str ], template : str ) -> str : ...
740
- @overload
741
- def expand (self : Match [bytes ], template : ReadableBuffer ) -> bytes : ...
742
- # group() returns "AnyStr" or "AnyStr | None", depending on the pattern.
743
- @overload
744
- def group (self , __group : _Literal [0 ] = ...) -> AnyStr : ...
745
- @overload
746
- def group (self , __group : str | int ) -> AnyStr | Any : ...
747
- @overload
748
- def group (self , __group1 : str | int , __group2 : str | int , * groups : str | int ) -> tuple [AnyStr | Any , ...]: ...
749
- # Each item of groups()'s return tuple is either "AnyStr" or
750
- # "AnyStr | None", depending on the pattern.
751
- @overload
752
- def groups (self ) -> tuple [AnyStr | Any , ...]: ...
753
- @overload
754
- def groups (self , default : _T ) -> tuple [AnyStr | _T , ...]: ...
755
- # Each value in groupdict()'s return dict is either "AnyStr" or
756
- # "AnyStr | None", depending on the pattern.
757
- @overload
758
- def groupdict (self ) -> dict [str , AnyStr | Any ]: ...
759
- @overload
760
- def groupdict (self , default : _T ) -> dict [str , AnyStr | _T ]: ...
761
- def start (self , __group : int | str = ...) -> int : ...
762
- def end (self , __group : int | str = ...) -> int : ...
763
- def span (self , __group : int | str = ...) -> tuple [int , int ]: ...
764
- @property
765
- def regs (self ) -> tuple [tuple [int , int ], ...]: ... # undocumented
766
- # __getitem__() returns "AnyStr" or "AnyStr | None", depending on the pattern.
767
- @overload
768
- def __getitem__ (self , __key : _Literal [0 ]) -> AnyStr : ...
769
- @overload
770
- def __getitem__ (self , __key : int | str ) -> AnyStr | Any : ...
771
- def __copy__ (self ) -> Match [AnyStr ]: ...
772
- def __deepcopy__ (self , __memo : Any ) -> Match [AnyStr ]: ...
773
- if sys .version_info >= (3 , 9 ):
774
- def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
775
-
776
- @_final
777
- class Pattern (Generic [AnyStr ]):
778
- @property
779
- def flags (self ) -> int : ...
780
- @property
781
- def groupindex (self ) -> Mapping [str , int ]: ...
782
- @property
783
- def groups (self ) -> int : ...
784
- @property
785
- def pattern (self ) -> AnyStr : ...
786
- @overload
787
- def search (self : Pattern [str ], string : str , pos : int = ..., endpos : int = ...) -> Match [str ] | None : ...
788
- @overload
789
- def search (self : Pattern [bytes ], string : ReadableBuffer , pos : int = ..., endpos : int = ...) -> Match [bytes ] | None : ...
790
- @overload
791
- def match (self : Pattern [str ], string : str , pos : int = ..., endpos : int = ...) -> Match [str ] | None : ...
792
- @overload
793
- def match (self : Pattern [bytes ], string : ReadableBuffer , pos : int = ..., endpos : int = ...) -> Match [bytes ] | None : ...
794
- @overload
795
- def fullmatch (self : Pattern [str ], string : str , pos : int = ..., endpos : int = ...) -> Match [str ] | None : ...
796
- @overload
797
- def fullmatch (self : Pattern [bytes ], string : ReadableBuffer , pos : int = ..., endpos : int = ...) -> Match [bytes ] | None : ...
798
- @overload
799
- def split (self : Pattern [str ], string : str , maxsplit : int = ...) -> list [str | Any ]: ...
800
- @overload
801
- def split (self : Pattern [bytes ], string : ReadableBuffer , maxsplit : int = ...) -> list [bytes | Any ]: ...
802
- # return type depends on the number of groups in the pattern
803
- @overload
804
- def findall (self : Pattern [str ], string : str , pos : int = ..., endpos : int = ...) -> list [Any ]: ...
805
- @overload
806
- def findall (self : Pattern [bytes ], string : ReadableBuffer , pos : int = ..., endpos : int = ...) -> list [Any ]: ...
807
- @overload
808
- def finditer (self : Pattern [str ], string : str , pos : int = ..., endpos : int = ...) -> Iterator [Match [str ]]: ...
809
- @overload
810
- def finditer (self : Pattern [bytes ], string : ReadableBuffer , pos : int = ..., endpos : int = ...) -> Iterator [Match [bytes ]]: ...
811
- @overload
812
- def sub (self : Pattern [str ], repl : str | Callable [[Match [str ]], str ], string : str , count : int = ...) -> str : ...
813
- @overload
814
- def sub (
815
- self : Pattern [bytes ],
816
- repl : ReadableBuffer | Callable [[Match [bytes ]], ReadableBuffer ],
817
- string : ReadableBuffer ,
818
- count : int = ...,
819
- ) -> bytes : ...
820
- @overload
821
- def subn (self : Pattern [str ], repl : str | Callable [[Match [str ]], str ], string : str , count : int = ...) -> tuple [str , int ]: ...
822
- @overload
823
- def subn (
824
- self : Pattern [bytes ],
825
- repl : ReadableBuffer | Callable [[Match [bytes ]], ReadableBuffer ],
826
- string : ReadableBuffer ,
827
- count : int = ...,
828
- ) -> tuple [bytes , int ]: ...
829
- def __copy__ (self ) -> Pattern [AnyStr ]: ...
830
- def __deepcopy__ (self , __memo : Any ) -> Pattern [AnyStr ]: ...
831
- if sys .version_info >= (3 , 9 ):
832
- def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
833
-
834
707
# Functions
835
708
836
709
_get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed
0 commit comments