From 5608eca99b4f73c0ff29a3ebc753435096114faf Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Tue, 26 Dec 2023 17:22:29 +0000 Subject: [PATCH] Fix(stdlib/re): Return `AnyStr | None` for regex groups --- stdlib/re.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index ec532ca3cffe..b1c84e47dc06 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -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: ... @@ -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):