Skip to content

regex: accept buffers #7680

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

Merged
merged 5 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
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
281 changes: 214 additions & 67 deletions stubs/regex/regex/_regex.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Self
from _typeshed import ReadableBuffer, Self
from collections.abc import Callable, Mapping
from typing import Any, AnyStr, Generic, TypeVar, overload
from typing_extensions import Literal, final
Expand All @@ -7,126 +7,273 @@ _T = TypeVar("_T")

@final
class Pattern(Generic[AnyStr]):
pattern: AnyStr
flags: int
groups: int
groupindex: Mapping[str, int]
named_lists: Mapping[str, frozenset[AnyStr]]
@property
def flags(self) -> int: ...
@property
def groupindex(self) -> Mapping[str, int]: ...
@property
def groups(self) -> int: ...
@property
def pattern(self) -> AnyStr: ...
@property
def named_lists(self) -> Mapping[str, frozenset[AnyStr]]: ...
@overload
def search(
self,
string: AnyStr,
pos: int | None = ...,
endpos: int | None = ...,
self: Pattern[str],
string: str,
pos: int = ...,
endpos: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Match[str] | None: ...
@overload
def search(
self: Pattern[bytes],
string: ReadableBuffer,
pos: int = ...,
endpos: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Match[AnyStr] | None: ...
) -> Match[bytes] | None: ...
@overload
def match(
self,
string: AnyStr,
pos: int | None = ...,
endpos: int | None = ...,
self: Pattern[str],
string: str,
pos: int = ...,
endpos: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Match[str] | None: ...
@overload
def match(
self: Pattern[bytes],
string: ReadableBuffer,
pos: int = ...,
endpos: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Match[AnyStr] | None: ...
) -> Match[bytes] | None: ...
@overload
def fullmatch(
self,
string: AnyStr,
pos: int | None = ...,
endpos: int | None = ...,
self: Pattern[str],
string: str,
pos: int = ...,
endpos: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Match[str] | None: ...
@overload
def fullmatch(
self: Pattern[bytes],
string: ReadableBuffer,
pos: int = ...,
endpos: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Match[AnyStr] | None: ...
) -> Match[bytes] | None: ...
@overload
def split(
self: Pattern[str], string: str, maxsplit: int = ..., concurrent: bool | None = ..., timeout: float | None = ...
) -> list[str | Any]: ...
@overload
def split(
self, string: AnyStr, maxsplit: int = ..., concurrent: bool | None = ..., timeout: float | None = ...
) -> list[AnyStr | Any]: ...
self: Pattern[bytes],
string: ReadableBuffer,
maxsplit: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> list[bytes | Any]: ...
@overload
def splititer(
self, string: AnyStr, maxsplit: int = ..., concurrent: bool | None = ..., timeout: float | None = ...
) -> Splitter[AnyStr]: ...
self: Pattern[str], string: str, maxsplit: int = ..., concurrent: bool | None = ..., timeout: float | None = ...
) -> Splitter[str]: ...
@overload
def splititer(
self: Pattern[bytes],
string: ReadableBuffer,
maxsplit: int = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Splitter[bytes]: ...
@overload
def findall(
self,
string: AnyStr,
pos: int | None = ...,
endpos: int | None = ...,
self: Pattern[str],
string: str,
pos: int = ...,
endpos: int = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> list[Any]: ...
@overload
def findall(
self: Pattern[bytes],
string: ReadableBuffer,
pos: int = ...,
endpos: int = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> list[Any]: ...
@overload
def finditer(
self,
string: AnyStr,
self: Pattern[str],
string: str,
pos: int = ...,
endpos: int = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Scanner[str]: ...
@overload
def finditer(
self: Pattern[bytes],
string: ReadableBuffer,
pos: int = ...,
endpos: int = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Scanner[bytes]: ...
@overload
def sub(
self: Pattern[str],
repl: str | Callable[[Match[str]], str],
string: str,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Scanner[AnyStr]: ...
) -> str: ...
@overload
def sub(
self,
repl: AnyStr | Callable[[Match[AnyStr]], AnyStr],
string: AnyStr,
self: Pattern[bytes],
repl: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> AnyStr: ...
) -> bytes: ...
@overload
def subf(
self,
format: AnyStr | Callable[[Match[AnyStr]], AnyStr],
string: AnyStr,
self: Pattern[str],
format: str | Callable[[Match[str]], str],
string: str,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> str: ...
@overload
def subf(
self: Pattern[bytes],
format: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> bytes: ...
@overload
def subn(
self: Pattern[str],
repl: str | Callable[[Match[str]], str],
string: str,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> AnyStr: ...
) -> tuple[str, int]: ...
@overload
def subn(
self,
repl: AnyStr | Callable[[Match[AnyStr]], AnyStr],
string: AnyStr,
self: Pattern[bytes],
repl: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> tuple[bytes, int]: ...
@overload
def subfn(
self: Pattern[str],
format: str | Callable[[Match[str]], str],
string: str,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> tuple[AnyStr, int]: ...
) -> tuple[str, int]: ...
@overload
def subfn(
self,
format: AnyStr | Callable[[Match[AnyStr]], AnyStr],
string: AnyStr,
self: Pattern[bytes],
format: ReadableBuffer | Callable[[Match[bytes]], ReadableBuffer],
string: ReadableBuffer,
count: int = ...,
flags: int = ...,
pos: int | None = ...,
endpos: int | None = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> tuple[AnyStr, int]: ...
) -> tuple[bytes, int]: ...
@overload
def scanner(
self,
string: AnyStr,
self: Pattern[str],
string: str,
pos: int | None = ...,
endpos: int | None = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Scanner[AnyStr]: ...
) -> Scanner[str]: ...
@overload
def scanner(
self: Pattern[bytes],
string: bytes,
pos: int | None = ...,
endpos: int | None = ...,
overlapped: bool = ...,
concurrent: bool | None = ...,
timeout: float | None = ...,
) -> Scanner[bytes]: ...

@final
class Match(Generic[AnyStr]):

re: Pattern[AnyStr]
string: AnyStr
pos: int
endpos: int
partial: bool
regs: tuple[tuple[int, int], ...]
fuzzy_counts: tuple[int, int, int]
fuzzy_changes: tuple[list[int], list[int], list[int]]
lastgroup: str | None
lastindex: int | None
@property
def pos(self) -> int: ...
@property
def endpos(self) -> int: ...
@property
def lastindex(self) -> int | None: ...
@property
def lastgroup(self) -> str | None: ...
@property
def string(self) -> AnyStr: ...
@property
def re(self) -> Pattern[AnyStr]: ...
@property
def partial(self) -> bool: ...
@property
def regs(self) -> tuple[tuple[int, int], ...]: ...
@property
def fuzzy_counts(self) -> tuple[int, int, int]: ...
@property
def fuzzy_changes(self) -> tuple[list[int], list[int], list[int]]: ...
@overload
def group(self, __group: Literal[0] = ...) -> AnyStr: ...
@overload
Expand Down Expand Up @@ -180,16 +327,16 @@ class Match(Generic[AnyStr]):

@final
class Splitter(Generic[AnyStr]):

pattern: Pattern[AnyStr]
@property
def pattern(self) -> Pattern[AnyStr]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> AnyStr | Any: ...
def split(self) -> AnyStr | Any: ...

@final
class Scanner(Generic[AnyStr]):

pattern: Pattern[AnyStr]
@property
def pattern(self) -> Pattern[AnyStr]: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> Match[AnyStr]: ...
def match(self) -> Match[AnyStr] | None: ...
Expand Down
Loading