Skip to content

Fix(stdlib/re): Return AnyStr | None for regex groups #11203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions stdlib/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ class Match(Generic[AnyStr]):
@overload
def group(self, __group: Literal[0] = 0) -> AnyStr: ...
@overload
def group(self, __group: str | int) -> AnyStr | Any: ...
def group(self, __group: str | int) -> AnyStr | None: ...
@overload
def group(self, __group1: str | int, __group2: str | int, *groups: str | int) -> tuple[AnyStr | Any, ...]: ...
def group(self, __group1: str | int, __group2: str | int, *groups: str | int) -> tuple[AnyStr | None, ...]: ...
# Each item of groups()'s return tuple is either "AnyStr" or
# "AnyStr | None", depending on the pattern.
@overload
def groups(self) -> tuple[AnyStr | Any, ...]: ...
def groups(self) -> tuple[AnyStr | None, ...]: ...
@overload
def groups(self, default: _T) -> tuple[AnyStr | _T, ...]: ...
# Each value in groupdict()'s return dict is either "AnyStr" or
# "AnyStr | None", depending on the pattern.
@overload
def groupdict(self) -> dict[str, AnyStr | Any]: ...
def groupdict(self) -> dict[str, AnyStr | None]: ...
@overload
def groupdict(self, default: _T) -> dict[str, AnyStr | _T]: ...
def start(self, __group: int | str = 0) -> int: ...
Expand All @@ -98,7 +98,7 @@ class Match(Generic[AnyStr]):
@overload
def __getitem__(self, __key: Literal[0]) -> AnyStr: ...
@overload
def __getitem__(self, __key: int | str) -> AnyStr | Any: ...
def __getitem__(self, __key: int | str) -> AnyStr | None: ...
def __copy__(self) -> Match[AnyStr]: ...
def __deepcopy__(self, __memo: Any) -> Match[AnyStr]: ...
if sys.version_info >= (3, 9):
Expand Down