Use MaybeNone (alias to Any) when applicable (#12855)

This commit is contained in:
Oleh Prypin
2024-10-18 23:07:52 +02:00
committed by GitHub
parent 7fb84668fc
commit b2f68ec2fe
10 changed files with 43 additions and 41 deletions

View File

@@ -2,7 +2,7 @@ import enum
import sre_compile
import sre_constants
import sys
from _typeshed import ReadableBuffer
from _typeshed import MaybeNone, ReadableBuffer
from collections.abc import Callable, Iterator, Mapping
from typing import Any, AnyStr, Generic, Literal, TypeVar, final, overload
from typing_extensions import TypeAlias
@@ -90,19 +90,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 | MaybeNone: ...
@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 | MaybeNone, ...]: ...
# 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 | MaybeNone, ...]: ...
@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 | MaybeNone]: ...
@overload
def groupdict(self, default: _T) -> dict[str, AnyStr | _T]: ...
def start(self, group: int | str = 0, /) -> int: ...
@@ -114,7 +114,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 | MaybeNone: ...
def __copy__(self) -> Match[AnyStr]: ...
def __deepcopy__(self, memo: Any, /) -> Match[AnyStr]: ...
if sys.version_info >= (3, 9):
@@ -151,11 +151,11 @@ class Pattern(Generic[AnyStr]):
@overload
def fullmatch(self, string: AnyStr, pos: int = 0, endpos: int = sys.maxsize) -> Match[AnyStr] | None: ...
@overload
def split(self: Pattern[str], string: str, maxsplit: int = 0) -> list[str | Any]: ...
def split(self: Pattern[str], string: str, maxsplit: int = 0) -> list[str | MaybeNone]: ...
@overload
def split(self: Pattern[bytes], string: ReadableBuffer, maxsplit: int = 0) -> list[bytes | Any]: ...
def split(self: Pattern[bytes], string: ReadableBuffer, maxsplit: int = 0) -> list[bytes | MaybeNone]: ...
@overload
def split(self, string: AnyStr, maxsplit: int = 0) -> list[AnyStr | Any]: ...
def split(self, string: AnyStr, maxsplit: int = 0) -> list[AnyStr | MaybeNone]: ...
# return type depends on the number of groups in the pattern
@overload
def findall(self: Pattern[str], string: str, pos: int = 0, endpos: int = sys.maxsize) -> list[Any]: ...
@@ -270,11 +270,11 @@ def fullmatch(pattern: str | Pattern[str], string: str, flags: _FlagsType = 0) -
@overload
def fullmatch(pattern: bytes | Pattern[bytes], string: ReadableBuffer, flags: _FlagsType = 0) -> Match[bytes] | None: ...
@overload
def split(pattern: str | Pattern[str], string: str, maxsplit: int = 0, flags: _FlagsType = 0) -> list[str | Any]: ...
def split(pattern: str | Pattern[str], string: str, maxsplit: int = 0, flags: _FlagsType = 0) -> list[str | MaybeNone]: ...
@overload
def split(
pattern: bytes | Pattern[bytes], string: ReadableBuffer, maxsplit: int = 0, flags: _FlagsType = 0
) -> list[bytes | Any]: ...
) -> list[bytes | MaybeNone]: ...
@overload
def findall(pattern: str | Pattern[str], string: str, flags: _FlagsType = 0) -> list[Any]: ...
@overload