Skip to content
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

Make regex methods accept all buffer types as inputs #7158

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3344316
Make `mmap.mmap` extend `bytearray`
itaisteinherz Feb 7, 2022
6039732
Extend `ReadableBuffer` instead of `bytearray`
itaisteinherz Feb 8, 2022
74aa464
Fixup
itaisteinherz Feb 8, 2022
8666c61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 8, 2022
fdd90cd
Change `AnyStr` to include `ByteString` instead of `bytes`
itaisteinherz Feb 8, 2022
634c867
Merge branch 'feature/mmap-bytearray' of https://github.com/itaistein…
itaisteinherz Feb 8, 2022
efe5ee0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 8, 2022
6978ce6
Revert unwanted changes
itaisteinherz Feb 14, 2022
24e2a34
Finish reverting
itaisteinherz Feb 14, 2022
b9b1176
Fix PoC
itaisteinherz Feb 14, 2022
2ded7aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2022
eb0e953
Attempt to create custom type for regex strings
itaisteinherz Feb 14, 2022
38f5996
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2022
1a56af6
Fixup
itaisteinherz Feb 14, 2022
e26ef4e
Fix regex string typevar
itaisteinherz Feb 14, 2022
884af92
Update `Match` to use `RegexString`
itaisteinherz Feb 14, 2022
c9af022
Fix extended typevar
itaisteinherz Feb 14, 2022
6e320ae
Attempt to fix
itaisteinherz Feb 14, 2022
d3094f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2022
d775b51
Remove unused imports
itaisteinherz Feb 14, 2022
d97f24a
Merge branch 'feature/mmap-bytearray' of https://github.com/itaistein…
itaisteinherz Feb 14, 2022
c63f691
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2022
ee5573a
Fix linting
itaisteinherz Feb 14, 2022
6d470e2
Merge branch 'feature/mmap-bytearray' of https://github.com/itaistein…
itaisteinherz Feb 14, 2022
85a5004
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2022
46af759
Ignore linting error
itaisteinherz Feb 14, 2022
d9e68ac
Fixup old changes
itaisteinherz Feb 14, 2022
0fe7ca3
Revert last changes
itaisteinherz Feb 18, 2022
c4f23f7
Add second typevar argument to `Match`
itaisteinherz Feb 19, 2022
e26ab0c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 19, 2022
a410b16
`re.match` with `mmap.mmap` PoC
itaisteinherz Feb 19, 2022
7314338
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 19, 2022
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
2 changes: 2 additions & 0 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctyp
# Same as _WriteableBuffer, but also includes read-only buffer types (like bytes).
ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer] # stable

MatchString = TypeVar("MatchString", bound=str | bytes | ReadableBuffer)

# stable
if sys.version_info >= (3, 10):
from types import NoneType as NoneType
Expand Down
6 changes: 4 additions & 2 deletions stdlib/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import sys
from sre_constants import error as error
from typing import Any, AnyStr, Callable, Iterator, Union, overload

from stdlib._typeshed import MatchString

# ----- re variables and constants -----
if sys.version_info >= (3, 7):
from typing import Match as Match, Pattern as Pattern
Expand Down Expand Up @@ -60,9 +62,9 @@ def search(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Match[An
@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: ...
def match(pattern: AnyStr, string: MatchString, flags: _FlagsType = ...) -> Match[AnyStr, MatchString] | None: ...
@overload
def match(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Match[AnyStr] | None: ...
def match(pattern: Pattern[AnyStr], string: MatchString, flags: _FlagsType = ...) -> Match[AnyStr, MatchString] | None: ...

# New in Python 3.4
@overload
Expand Down
11 changes: 6 additions & 5 deletions stdlib/typing.pyi
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 MatchString, ReadableBuffer, Self, SupportsKeysAndGetItem, T_ReadableBuffer
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
Expand Down Expand Up @@ -587,12 +587,12 @@ class TextIO(IO[str]):
class ByteString(Sequence[int], metaclass=ABCMeta): ...

@_final
class Match(Generic[AnyStr]):
class Match(Generic[AnyStr, MatchString]):
pos: int
endpos: int
lastindex: int | None
lastgroup: str | None
string: AnyStr
string: MatchString

# The regular expression object whose match() or search() method produced
# this match instance.
Expand Down Expand Up @@ -636,8 +636,9 @@ class Pattern(Generic[AnyStr]):
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 search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr, AnyStr] | None: ...
def match(self, string: MatchString, pos: int = ..., endpos: int = ...) -> Match[AnyStr, MatchString] | 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]: ...
Expand Down