GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — gh-86519: Add prefixmatch APIs to the re module by gpshead · Pull Request #31137 · python/cpython Conversation
|
|
Did we actually reached a consensus on DPO for that feature to be merged? I thought there were some issues, especially with the fact that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yes, I think the 24 hearts on Greg's https://discuss.python.org/t/add-re-prefixmatch-deprecate-re-match/105927/20 is a pretty good sign. The only other posts with double-digit hearts are also in support: the OP (10), a docs suggestion from Tim (14), a name suggestion (
Whatever the third-party |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Non-blocking docs suggestion:
Use prefixmatch pretty much throughout, except to mention match is the alias (plus version changed etc.), which you've mostly already done here.
We can also update other places like the regex HOWTO to prefer the new name, but this can also be in a followup.
Bike shed colour:
I'm fine with either prefixmatch and startswith.
Pro for prefixmatch: it keeps the "match" part, which might help remind people when they see match: "oh, wait, is this the lopsided prefixmatch or fullmatch? I'd better double check the docs and use one of those descriptive names or instead search with explicit anchors."
Soft deprecation:
We're discouraging in docs and not planning on removing. Sounds like soft deprecation. I'd be fine with soft deprecating too, but that could also be another discussion once this is done (if anyone has energy for that!).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I'm similarly inclined to stick with lots of what look like good comments on the docs here and thoughts on how to document this to digest from the discuss thread. i'll work on getting the doc edits in and see if it looks like it needs more review after that. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Apply suggestions from hugovk and hauntsaninja reviews:
- List prefixmatch before match in function/method signatures
- Use prefixmatch exclusively in examples, remove redundant match duplicates
- Remove interchangeable paragraph (covered by prefixmatch-vs-match section)
- Rename section to "search() vs. prefixmatch()"
- Add .. note:: directive for MULTILINE caveat
- Fix time-sensitive wording ("very recent Python", "never")
- Fix alphabetical ordering in whatsnew/3.15.rst
- Fix comment grammar in Lib/re/__init__.py
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace the copy_prefixmatch_method_def_to_match() runtime memcpy with static struct initializers that reuse the Clinic-generated prefixmatch parser directly. This avoids duplicating argument parsing boilerplate while keeping everything initialized at compile time. Add Py_DEBUG assertions in sre_exec to verify the match and prefixmatch method table entries remain identical except for ml_name. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The "Removed" heading underline was exactly 7 '=' characters, which triggers the check-merge-conflict pre-commit hook as a false positive. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Refactor test_match_getitem to use a helper method instead of a for loop, keeping the assertion lines at their original indentation to preserve git line attribution history. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was an error while loading. Please reload this page.
|
merged, thanks for everyones reviews and discussions! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Adds `prefixmatch` APIs to the re module as an alternate name for our long existing `match` APIs to help alleviate a common Python confusion for those coming from other languages regular expression libraries. These alleviate common confusion around what "match" means as Python is different than other popular languages regex libraries in our use of the term as an API name. The original `match` names are **NOT being deprecated**. Source tooling like linters, IDEs, and LLMs could suggest using `prefixmatch` instead of match to improve code health and reduce cognitive burden of understanding the intent of code when configured for a modern minimum Python version. See the documentation changes for a better description. Discussions took place in the PR, in the issue, and finally at https://discuss.python.org/t/add-re-prefixmatch-deprecate-re-match/105927 Co-Authored-By: Claude Opus 4.5 <[email protected]> Co-authored-by: Shantanu <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]>
Please see PR #148096. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Adds `prefixmatch` APIs to the re module as an alternate name for our long existing `match` APIs to help alleviate a common Python confusion for those coming from other languages regular expression libraries. These alleviate common confusion around what "match" means as Python is different than other popular languages regex libraries in our use of the term as an API name. The original `match` names are **NOT being deprecated**. Source tooling like linters, IDEs, and LLMs could suggest using `prefixmatch` instead of match to improve code health and reduce cognitive burden of understanding the intent of code when configured for a modern minimum Python version. See the documentation changes for a better description. Discussions took place in the PR, in the issue, and finally at https://discuss.python.org/t/add-re-prefixmatch-deprecate-re-match/105927 Co-Authored-By: Claude Opus 4.5 <[email protected]> Co-authored-by: Shantanu <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]>
## Summary The example for [FURB167](https://docs.astral.sh/ruff/rules/regex-flag-alias/#regex-flag-alias-furb167) has `re.match` with an `^` anchor to match the start of the string: ```python if re.match("^hello", "hello world", re.I): ``` But `re.match` already implicitly matches the start of the string: https://docs.python.org/3/library/re.html#search-vs-match Let's change the example to `re.search` so the anchor isn't redundant. (The anchor's actually irrelevant to the example for this rule about long or short flag names.) (Aside: There's a discussion about adding `re.prefixmatch` and [soft] deprecating `re.match` because of the confusion around it: https://discuss.python.org/t/add-re-prefixmatch-deprecate-re-match/105927, python/cpython#86519, python/cpython#31137.) ## Test Plan <!-- How was it tested? --> 1. Create feature branch 2. Push to my fork to run CI 3. Realise feature branches are disabled for forks in Ruff CI 4. Merge feature branch to my `main` 5. Push that 6. Be happy I did, because it failed because I missed something 7. Fixup, pushup 8. Passes [🎉](https://github.com/hugovk/ruff/actions/runs/21524112749)
See python/cpython#31137 for more details
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.