From 8fc144ee3253d26ed78275211b21c82f058ea6e5 Mon Sep 17 00:00:00 2001 From: jpy-git Date: Thu, 30 Dec 2021 18:32:23 +0000 Subject: [PATCH 1/5] Remove unnecessary overrides from re --- stdlib/re.pyi | 68 +++++++++++------------------------------------ stdlib/typing.pyi | 12 +++------ 2 files changed, 18 insertions(+), 62 deletions(-) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 01a60d170c50..5eec3c22adb7 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -1,7 +1,7 @@ import enum import sys from sre_constants import error as error -from typing import Any, AnyStr, Callable, Iterator, Union, overload +from typing import Any, AnyStr, Callable, Iterator, Union # ----- re variables and constants ----- if sys.version_info >= (3, 7): @@ -51,67 +51,29 @@ if sys.version_info < (3, 7): # undocumented _pattern_type: type -@overload -def compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]: ... -@overload -def compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... -@overload -def search(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... -@overload -def search(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... -@overload -def match(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... -@overload -def match(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... +def compile(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... +def search(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... +def match(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... # New in Python 3.4 -@overload -def fullmatch(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... -@overload -def fullmatch(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... -@overload -def split(pattern: AnyStr, string: AnyStr, maxsplit: int = ..., flags: _FlagsType = ...) -> list[AnyStr | Any]: ... -@overload -def split(pattern: Pattern[AnyStr], string: AnyStr, maxsplit: int = ..., flags: _FlagsType = ...) -> list[AnyStr | Any]: ... -@overload -def findall(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> list[Any]: ... -@overload -def findall(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> list[Any]: ... +def fullmatch(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... +def split( + pattern: AnyStr | Pattern[AnyStr], string: AnyStr, maxsplit: int = ..., flags: _FlagsType = ... +) -> list[AnyStr | Any]: ... +def findall(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> list[Any]: ... # Return an iterator yielding match objects over all non-overlapping matches # for the RE pattern in string. The string is scanned left-to-right, and # matches are returned in the order found. Empty matches are included in the # result unless they touch the beginning of another match. -@overload -def finditer(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Iterator[Match[AnyStr]]: ... -@overload -def finditer(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Iterator[Match[AnyStr]]: ... -@overload -def sub(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int = ..., flags: _FlagsType = ...) -> AnyStr: ... -@overload +def finditer(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Iterator[Match[AnyStr]]: ... def sub( - pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: _FlagsType = ... + pattern: AnyStr | Pattern[AnyStr], + repl: AnyStr | Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, + count: int = ..., + flags: _FlagsType = ..., ) -> AnyStr: ... -@overload -def sub(pattern: Pattern[AnyStr], repl: AnyStr, string: AnyStr, count: int = ..., flags: _FlagsType = ...) -> AnyStr: ... -@overload -def sub( - pattern: Pattern[AnyStr], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: _FlagsType = ... -) -> AnyStr: ... -@overload -def subn(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int = ..., flags: _FlagsType = ...) -> tuple[AnyStr, int]: ... -@overload -def subn( - pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: _FlagsType = ... -) -> tuple[AnyStr, int]: ... -@overload -def subn( - pattern: Pattern[AnyStr], repl: AnyStr, string: AnyStr, count: int = ..., flags: _FlagsType = ... -) -> tuple[AnyStr, int]: ... -@overload -def subn( - pattern: Pattern[AnyStr], repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ..., flags: _FlagsType = ... -) -> tuple[AnyStr, int]: ... def escape(pattern: AnyStr) -> AnyStr: ... def purge() -> None: ... def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index b4817f93f332..23ad07cad0ec 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -622,17 +622,11 @@ class Pattern(Generic[AnyStr]): def search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ... def match(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ... def fullmatch(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ... - def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ... + def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr | Any]: ... def findall(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> list[Any]: ... def finditer(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Iterator[Match[AnyStr]]: ... - @overload - def sub(self, repl: AnyStr, string: AnyStr, count: int = ...) -> AnyStr: ... - @overload - def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ... - @overload - def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ... - @overload - def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ... + def sub(self, repl: AnyStr | Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ... + def subn(self, repl: AnyStr | Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... From a96868321995e283eeb22479065a65873ae68122 Mon Sep 17 00:00:00 2001 From: jpy-git Date: Thu, 30 Dec 2021 18:42:27 +0000 Subject: [PATCH 2/5] Re-add subn --- stdlib/re.pyi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 5eec3c22adb7..a0be723c5303 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -74,6 +74,13 @@ def sub( count: int = ..., flags: _FlagsType = ..., ) -> AnyStr: ... +def subn( + pattern: AnyStr | Pattern[AnyStr], + repl: AnyStr | Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, + count: int = ..., + flags: _FlagsType = ..., +) -> tuple[AnyStr, int]: ... def escape(pattern: AnyStr) -> AnyStr: ... def purge() -> None: ... def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... From 3e7b90ffa8c9650c59932e1668aa761a1bc0c5d9 Mon Sep 17 00:00:00 2001 From: Joseph Young <80432516+jpy-git@users.noreply.github.com> Date: Thu, 30 Dec 2021 19:00:47 +0000 Subject: [PATCH 3/5] Update stdlib/re.pyi Co-authored-by: Alex Waygood --- stdlib/re.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index a0be723c5303..61c96a880335 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -55,7 +55,6 @@ def compile(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Patte def search(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... def match(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... -# New in Python 3.4 def fullmatch(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... def split( pattern: AnyStr | Pattern[AnyStr], string: AnyStr, maxsplit: int = ..., flags: _FlagsType = ... From a8afbd083133e8988e363a918d1f4d6ba6fb97ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Dec 2021 19:01:53 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/re.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 61c96a880335..e8657c681fe3 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -54,7 +54,6 @@ if sys.version_info < (3, 7): def compile(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... def search(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... def match(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... - def fullmatch(pattern: AnyStr | Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ... def split( pattern: AnyStr | Pattern[AnyStr], string: AnyStr, maxsplit: int = ..., flags: _FlagsType = ... From 1a1735f7585809c7b091a33b1c0baee10c7bf791 Mon Sep 17 00:00:00 2001 From: jpy-git Date: Thu, 30 Dec 2021 19:23:00 +0000 Subject: [PATCH 5/5] Remove split return type fix in favour of #6763 --- stdlib/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 23ad07cad0ec..a924df69bd54 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -622,7 +622,7 @@ class Pattern(Generic[AnyStr]): def search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ... def match(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ... def fullmatch(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ... - def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr | Any]: ... + def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ... def findall(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> list[Any]: ... def finditer(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Iterator[Match[AnyStr]]: ... def sub(self, repl: AnyStr | Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ...