Buffer support for re (#7679)

This commit is contained in:
Jelle Zijlstra
2022-04-23 18:28:35 -07:00
committed by GitHub
parent 5dad506bf2
commit 02e0c98d62
3 changed files with 86 additions and 48 deletions

View File

@@ -1,6 +1,6 @@
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
from _typeshed import Self as TypeshedSelf, SupportsKeysAndGetItem
from _typeshed import ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final
@@ -1079,7 +1079,10 @@ class Match(Generic[AnyStr]):
# this match instance.
@property
def re(self) -> Pattern[AnyStr]: ...
def expand(self, template: AnyStr) -> AnyStr: ...
@overload
def expand(self: Match[str], template: str) -> str: ...
@overload
def expand(self: Match[bytes], template: ReadableBuffer) -> bytes: ...
# group() returns "AnyStr" or "AnyStr | None", depending on the pattern.
@overload
def group(self, __group: _Literal[0] = ...) -> AnyStr: ...
@@ -1124,20 +1127,49 @@ class Pattern(Generic[AnyStr]):
def groups(self) -> int: ...
@property
def pattern(self) -> 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 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: ...
def search(self: Pattern[str], string: str, pos: int = ..., endpos: int = ...) -> Match[str] | None: ...
@overload
def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ...
def search(self: Pattern[bytes], string: ReadableBuffer, pos: int = ..., endpos: int = ...) -> Match[bytes] | None: ...
@overload
def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ...
def match(self: Pattern[str], string: str, pos: int = ..., endpos: int = ...) -> Match[str] | None: ...
@overload
def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ...
def match(self: Pattern[bytes], string: ReadableBuffer, pos: int = ..., endpos: int = ...) -> Match[bytes] | None: ...
@overload
def fullmatch(self: Pattern[str], string: str, pos: int = ..., endpos: int = ...) -> Match[str] | None: ...
@overload
def fullmatch(self: Pattern[bytes], string: ReadableBuffer, pos: int = ..., endpos: int = ...) -> Match[bytes] | None: ...
@overload
def split(self: Pattern[str], string: str, maxsplit: int = ...) -> list[str | Any]: ...
@overload
def split(self: Pattern[bytes], string: ReadableBuffer, maxsplit: int = ...) -> list[bytes | Any]: ...
# return type depends on the number of groups in the pattern
@overload
def findall(self: Pattern[str], string: str, pos: int = ..., endpos: int = ...) -> list[Any]: ...
@overload
def findall(self: Pattern[bytes], string: ReadableBuffer, pos: int = ..., endpos: int = ...) -> list[Any]: ...
@overload
def finditer(self: Pattern[str], string: str, pos: int = ..., endpos: int = ...) -> Iterator[Match[str]]: ...
@overload
def finditer(self: Pattern[bytes], string: ReadableBuffer, pos: int = ..., endpos: int = ...) -> Iterator[Match[bytes]]: ...
@overload
def sub(self: Pattern[str], repl: str | Callable[[Match[str]], str], string: str, count: int = ...) -> str: ...
@overload
def sub(
self: Pattern[bytes],
repl: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
count: int = ...,
) -> bytes: ...
@overload
def subn(self: Pattern[str], repl: str | Callable[[Match[str]], str], string: str, count: int = ...) -> tuple[str, int]: ...
@overload
def subn(
self: Pattern[bytes],
repl: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
count: int = ...,
) -> tuple[bytes, int]: ...
def __copy__(self) -> Pattern[AnyStr]: ...
def __deepcopy__(self, __memo: Any) -> Pattern[AnyStr]: ...
if sys.version_info >= (3, 9):