Draft
Conversation
provinzkraut
commented
Nov 11, 2025
| from . import inspect | ||
| from . import structs | ||
| from ._version import __version__ | ||
| from ._utils import RegexPatternProtocol |
Contributor
Author
There was a problem hiding this comment.
Do we want to publish this?
provinzkraut
commented
Nov 11, 2025
| static bool | ||
| ensure_is_re_pattern_compatible (PyObject *val, const char *param) { | ||
| if (PyUnicode_CheckExact(val)) return true; | ||
| if (PyObject_HasAttrString(val, "pattern") && PyObject_HasAttrString(val, "search")) { |
Contributor
Author
There was a problem hiding this comment.
This check is currently very rudimentary. How strict do we want to be with this? Another option would be to make the RegexPatternProtocol runtime checkable and then do an isinstance check here. That would certainly be more robust, but is it desirable?
provinzkraut
commented
Nov 11, 2025
| return cls(**kwargs) | ||
|
|
||
|
|
||
| class RegexPatternProtocol(typing.Protocol): |
Contributor
Author
There was a problem hiding this comment.
I've kept the required API as minimal as possible here.
provinzkraut
commented
Nov 11, 2025
| string: str, | ||
| pos: int = 0, | ||
| endpos: int = sys.maxsize, | ||
| ) -> object | None: ... |
Contributor
Author
There was a problem hiding this comment.
Returning object | None reflects how it's being used internally. This allows greater flexibility, since regex engines mustn't also comply with the re.Match protocol, and we're not doing anything with the match anyway
Contributor
Author
|
|
2dcea3f to
b979819
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implement #860.