-
-
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 2 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
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.
Another thought: how does this even work?
ReadableBuffer
is aUnion
which includesmmap.mmap
, which leads me to the conclusion that this should result in some sort of infinite type loop.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.
Update: this does lead to an error :) Will probably split up
WriteableBuffer
to fix this.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.
We should add it to the union, not use the union as a base class.
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.
What do you mean?
mmap.mmap
is already part ofWriteableBuffer
.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.
Oh, right. Then we shouldn't change it at all.
The original problem was that mmap wasn't accepted in re.match. If re.match accepts all buffers, then we should change its signature, not anything about mmap.
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.
Got it. Will look into
re.match
. Note that havingmmap.mmap
extendReadOnlyBuffer
does make some sense to me, though you're probably right.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.
Upon further research, it seems to me like a way to solve this would be to have
mmap.mmap
extendByteString
, and change the definition ofAnyStr
to:However, that would require a change in CPython. I could also create an
AnyStr
alternative, specific toPattern
, with this definition. One last option would be to havemmap.mmap
extendbytes
(akaReadOnlyBuffer
). What do you think?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.
We should not change AnyStr. That would require CPython runtime changes. We could use a separate typevar specific to regexes, but I'd have to look more into it to figure out whether that's feasible.