@@ -2,6 +2,7 @@ import collections # Needed by aliases like DefaultDict, see mypy issue 2986
22import sys
33from abc import ABCMeta , abstractmethod
44from types import BuiltinFunctionType , CodeType , FrameType , FunctionType , MethodType , ModuleType , TracebackType
5+ from typing_extensions import Literal as _Literal
56
67if sys .version_info >= (3 , 7 ):
78 from types import MethodDescriptorType , MethodWrapperType , WrapperDescriptorType
@@ -563,19 +564,35 @@ class Match(Generic[AnyStr]):
563564 # this match instance.
564565 re : Pattern [AnyStr ]
565566 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 .
567568 @overload
568- def group (self , __group : Union [ str , int ] = ...) -> AnyStr : ...
569+ def group (self , __group : _Literal [ 0 ] = ...) -> AnyStr : ...
569570 @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 ]: ...
573586 def start (self , __group : Union [int , str ] = ...) -> int : ...
574587 def end (self , __group : Union [int , str ] = ...) -> int : ...
575588 def span (self , __group : Union [int , str ] = ...) -> Tuple [int , int ]: ...
576589 @property
577590 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 : ...
579596 if sys .version_info >= (3 , 9 ):
580597 def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
581598
0 commit comments