Skip to content

Commit 3f6cec9

Browse files
authored
Fix Match.group problems (#3172)
* group() may return None values * group() allows to mix int and str arguments * Use concrete return type * Merge overloads
1 parent 6f01493 commit 3f6cec9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

stdlib/3/typing.pyi

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ from abc import abstractmethod, ABCMeta
55
from types import CodeType, FrameType, TracebackType
66
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
77

8+
if sys.version_info < (3, 8):
9+
from typing_extensions import Literal
10+
811
# Definitions of special type checking related constructs. Their definition
912
# are not used, so their value does not matter.
1013

@@ -526,15 +529,16 @@ class Match(Generic[AnyStr]):
526529
def expand(self, template: AnyStr) -> AnyStr: ...
527530

528531
@overload
529-
def group(self, group1: int = ...) -> AnyStr: ...
530-
@overload
531-
def group(self, group1: str) -> AnyStr: ...
532+
def group(self, __group: Literal[0] = ...) -> AnyStr: ...
532533
@overload
533-
def group(self, group1: int, group2: int,
534-
*groups: int) -> Sequence[AnyStr]: ...
534+
def group(self, __group: Union[str, int]) -> Optional[AnyStr]: ...
535535
@overload
536-
def group(self, group1: str, group2: str,
537-
*groups: str) -> Sequence[AnyStr]: ...
536+
def group(
537+
self,
538+
__group1: Union[str, int],
539+
__group2: Union[str, int],
540+
*groups: Union[str, int],
541+
) -> Tuple[Optional[AnyStr], ...]: ...
538542

539543
def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ...
540544
def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ...

0 commit comments

Comments
 (0)