-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make regex methods accept all buffer types as inputs #7158
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
Closed
itaisteinherz
wants to merge
32
commits into
python:master
from
itaisteinherz:feature/mmap-bytearray
Closed
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3344316
Make `mmap.mmap` extend `bytearray`
itaisteinherz 6039732
Extend `ReadableBuffer` instead of `bytearray`
itaisteinherz 74aa464
Fixup
itaisteinherz 8666c61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fdd90cd
Change `AnyStr` to include `ByteString` instead of `bytes`
itaisteinherz 634c867
Merge branch 'feature/mmap-bytearray' of https://github.com/itaistein…
itaisteinherz efe5ee0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6978ce6
Revert unwanted changes
itaisteinherz 24e2a34
Finish reverting
itaisteinherz b9b1176
Fix PoC
itaisteinherz 2ded7aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eb0e953
Attempt to create custom type for regex strings
itaisteinherz 38f5996
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1a56af6
Fixup
itaisteinherz e26ef4e
Fix regex string typevar
itaisteinherz 884af92
Update `Match` to use `RegexString`
itaisteinherz c9af022
Fix extended typevar
itaisteinherz 6e320ae
Attempt to fix
itaisteinherz d3094f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d775b51
Remove unused imports
itaisteinherz d97f24a
Merge branch 'feature/mmap-bytearray' of https://github.com/itaistein…
itaisteinherz c63f691
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ee5573a
Fix linting
itaisteinherz 6d470e2
Merge branch 'feature/mmap-bytearray' of https://github.com/itaistein…
itaisteinherz 85a5004
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 46af759
Ignore linting error
itaisteinherz d9e68ac
Fixup old changes
itaisteinherz 0fe7ca3
Revert last changes
itaisteinherz c4f23f7
Add second typevar argument to `Match`
itaisteinherz e26ab0c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a410b16
`re.match` with `mmap.mmap` PoC
itaisteinherz 7314338
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import collections # Needed by aliases like DefaultDict, see mypy issue 2986 | ||
import sys | ||
from _typeshed import Self, SupportsKeysAndGetItem | ||
from _typeshed import Self, StrOrBuffer, 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 | ||
|
@@ -587,69 +587,71 @@ class TextIO(IO[str]): | |
class ByteString(Sequence[int], metaclass=ABCMeta): ... | ||
|
||
@_final | ||
class Match(Generic[AnyStr]): | ||
class Match(Generic[StrOrBuffer]): | ||
pos: int | ||
endpos: int | ||
lastindex: int | None | ||
lastgroup: str | None | ||
string: AnyStr | ||
string: StrOrBuffer | ||
|
||
# The regular expression object whose match() or search() method produced | ||
# this match instance. | ||
re: Pattern[AnyStr] | ||
def expand(self, template: AnyStr) -> AnyStr: ... | ||
# group() returns "AnyStr" or "AnyStr | None", depending on the pattern. | ||
re: Pattern[StrOrBuffer] | ||
def expand(self, template: StrOrBuffer) -> StrOrBuffer: ... | ||
# group() returns "StrOrBuffer" or "StrOrBuffer | None", depending on the pattern. | ||
@overload | ||
def group(self, __group: _Literal[0] = ...) -> AnyStr: ... | ||
def group(self, __group: _Literal[0] = ...) -> StrOrBuffer: ... | ||
@overload | ||
def group(self, __group: str | int) -> AnyStr | Any: ... | ||
def group(self, __group: str | int) -> StrOrBuffer | Any: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't right: if you match on a memoryview, you get bytes objects from .group(), not memoryviews. |
||
@overload | ||
def group(self, __group1: str | int, __group2: str | int, *groups: str | int) -> tuple[AnyStr | Any, ...]: ... | ||
# Each item of groups()'s return tuple is either "AnyStr" or | ||
# "AnyStr | None", depending on the pattern. | ||
def group(self, __group1: str | int, __group2: str | int, *groups: str | int) -> tuple[StrOrBuffer | Any, ...]: ... | ||
# Each item of groups()'s return tuple is either "StrOrBuffer" or | ||
# "StrOrBuffer | None", depending on the pattern. | ||
@overload | ||
def groups(self) -> tuple[AnyStr | Any, ...]: ... | ||
def groups(self) -> tuple[StrOrBuffer | Any, ...]: ... | ||
@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. | ||
def groups(self, default: _T) -> tuple[StrOrBuffer | _T, ...]: ... | ||
# Each value in groupdict()'s return dict is either "StrOrBuffer" or | ||
# "StrOrBuffer | None", depending on the pattern. | ||
@overload | ||
def groupdict(self) -> dict[str, AnyStr | Any]: ... | ||
def groupdict(self) -> dict[str, StrOrBuffer | Any]: ... | ||
@overload | ||
def groupdict(self, default: _T) -> dict[str, AnyStr | _T]: ... | ||
def groupdict(self, default: _T) -> dict[str, StrOrBuffer | _T]: ... | ||
def start(self, __group: int | str = ...) -> int: ... | ||
def end(self, __group: int | str = ...) -> int: ... | ||
def span(self, __group: int | str = ...) -> tuple[int, int]: ... | ||
@property | ||
def regs(self) -> tuple[tuple[int, int], ...]: ... # undocumented | ||
# __getitem__() returns "AnyStr" or "AnyStr | None", depending on the pattern. | ||
# __getitem__() returns "StrOrBuffer" or "StrOrBuffer | None", depending on the pattern. | ||
@overload | ||
def __getitem__(self, __key: _Literal[0]) -> AnyStr: ... | ||
def __getitem__(self, __key: _Literal[0]) -> StrOrBuffer: ... | ||
@overload | ||
def __getitem__(self, __key: int | str) -> AnyStr | Any: ... | ||
def __getitem__(self, __key: int | str) -> StrOrBuffer | Any: ... | ||
if sys.version_info >= (3, 9): | ||
def __class_getitem__(cls, item: Any) -> GenericAlias: ... | ||
|
||
@_final | ||
class Pattern(Generic[AnyStr]): | ||
class Pattern(Generic[StrOrBuffer]): | ||
flags: int | ||
groupindex: Mapping[str, int] | ||
groups: int | ||
pattern: 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]]: ... | ||
pattern: StrOrBuffer | ||
def search(self, string: StrOrBuffer, pos: int = ..., endpos: int = ...) -> Match[StrOrBuffer] | None: ... | ||
def match(self, string: StrOrBuffer, pos: int = ..., endpos: int = ...) -> Match[StrOrBuffer] | None: ... | ||
def fullmatch(self, string: StrOrBuffer, pos: int = ..., endpos: int = ...) -> Match[StrOrBuffer] | None: ... | ||
def split(self, string: StrOrBuffer, maxsplit: int = ...) -> list[StrOrBuffer | Any]: ... | ||
def findall(self, string: StrOrBuffer, pos: int = ..., endpos: int = ...) -> list[Any]: ... | ||
def finditer(self, string: StrOrBuffer, pos: int = ..., endpos: int = ...) -> Iterator[Match[StrOrBuffer]]: ... | ||
@overload | ||
def sub(self, repl: AnyStr, string: AnyStr, count: int = ...) -> AnyStr: ... | ||
def sub(self, repl: StrOrBuffer, string: StrOrBuffer, count: int = ...) -> StrOrBuffer: ... | ||
@overload | ||
def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ... | ||
def sub(self, repl: Callable[[Match[StrOrBuffer]], StrOrBuffer], string: StrOrBuffer, count: int = ...) -> StrOrBuffer: ... | ||
@overload | ||
def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ... | ||
def subn(self, repl: StrOrBuffer, string: StrOrBuffer, count: int = ...) -> tuple[StrOrBuffer, int]: ... | ||
@overload | ||
def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ... | ||
def subn( | ||
self, repl: Callable[[Match[StrOrBuffer]], StrOrBuffer], string: StrOrBuffer, count: int = ... | ||
) -> tuple[StrOrBuffer, int]: ... | ||
if sys.version_info >= (3, 9): | ||
def __class_getitem__(cls, item: Any) -> GenericAlias: ... | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re.compile actually works only on str or bytes