@@ -2,6 +2,7 @@ import collections # Needed by aliases like DefaultDict, see mypy issue 2986
2
2
import sys
3
3
from abc import ABCMeta , abstractmethod
4
4
from types import BuiltinFunctionType , CodeType , FrameType , FunctionType , MethodType , ModuleType , TracebackType
5
+ from typing_extensions import Literal as _Literal
5
6
6
7
if sys .version_info >= (3 , 7 ):
7
8
from types import MethodDescriptorType , MethodWrapperType , WrapperDescriptorType
@@ -563,19 +564,35 @@ class Match(Generic[AnyStr]):
563
564
# this match instance.
564
565
re : Pattern [AnyStr ]
565
566
def expand (self , template : AnyStr ) -> AnyStr : ...
566
- # TODO: The return for a group may be None, except if __group is 0 or not given .
567
+ # group() returns "AnyStr" or "AnyStr | None", depending on the pattern .
567
568
@overload
568
- def group (self , __group : Union [ str , int ] = ...) -> AnyStr : ...
569
+ def group (self , __group : _Literal [ 0 ] = ...) -> AnyStr : ...
569
570
@overload
570
- def group (self , __group1 : Union [str , int ], __group2 : Union [str , int ], * groups : Union [str , int ]) -> Tuple [AnyStr , ...]: ...
571
- def groups (self , default : AnyStr = ...) -> Sequence [AnyStr ]: ...
572
- def groupdict (self , default : AnyStr = ...) -> dict [str , AnyStr ]: ...
571
+ def group (self , __group : str | int ) -> AnyStr | Any : ...
572
+ @overload
573
+ def group (self , __group1 : str | int , __group2 : str | int , * groups : str | int ) -> Tuple [AnyStr | Any , ...]: ...
574
+ # Each item of groups()'s return tuple is either "AnyStr" or
575
+ # "AnyStr | None", depending on the pattern.
576
+ @overload
577
+ def groups (self ) -> Tuple [AnyStr | Any , ...]: ...
578
+ @overload
579
+ def groups (self , default : _T ) -> Tuple [AnyStr | _T , ...]: ...
580
+ # Each value in groupdict()'s return dict is either "AnyStr" or
581
+ # "AnyStr | None", depending on the pattern.
582
+ @overload
583
+ def groupdict (self ) -> dict [str , AnyStr | Any ]: ...
584
+ @overload
585
+ def groupdict (self , default : _T ) -> dict [str , AnyStr | _T ]: ...
573
586
def start (self , __group : Union [int , str ] = ...) -> int : ...
574
587
def end (self , __group : Union [int , str ] = ...) -> int : ...
575
588
def span (self , __group : Union [int , str ] = ...) -> Tuple [int , int ]: ...
576
589
@property
577
590
def regs (self ) -> Tuple [Tuple [int , int ], ...]: ... # undocumented
578
- def __getitem__ (self , g : Union [int , str ]) -> AnyStr : ...
591
+ # __getitem__() returns "AnyStr" or "AnyStr | None", depending on the pattern.
592
+ @overload
593
+ def __getitem__ (self , __key : _Literal [0 ]) -> AnyStr : ...
594
+ @overload
595
+ def __getitem__ (self , __key : int | str ) -> AnyStr | Any : ...
579
596
if sys .version_info >= (3 , 9 ):
580
597
def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
581
598
@@ -586,7 +603,6 @@ class Pattern(Generic[AnyStr]):
586
603
pattern : AnyStr
587
604
def search (self , string : AnyStr , pos : int = ..., endpos : int = ...) -> Optional [Match [AnyStr ]]: ...
588
605
def match (self , string : AnyStr , pos : int = ..., endpos : int = ...) -> Optional [Match [AnyStr ]]: ...
589
- # New in Python 3.4
590
606
def fullmatch (self , string : AnyStr , pos : int = ..., endpos : int = ...) -> Optional [Match [AnyStr ]]: ...
591
607
def split (self , string : AnyStr , maxsplit : int = ...) -> list [AnyStr ]: ...
592
608
def findall (self , string : AnyStr , pos : int = ..., endpos : int = ...) -> list [Any ]: ...
0 commit comments