{{ message }}
gh-156185: Ignore all ASCII whitespace in re \p{} property names - #156304
Open
Georgefifth wants to merge 1 commit into
Open
Georgefifth wants to merge 1 commit into
Georgefifth wants to merge 1 commit into
Conversation
| # hyphens and underscores are not significant, and an initial "is" prefix | ||
| # is ignored (UAX #44 5.9, "Matching Rules", UAX44-LM3; | ||
| # Unicode property and value names are matched loosely: case, whitespace | ||
| # and hyphens and underscores are not significant, and an initial "is" |
| # prefix is ignored (UAX #44 5.9, "Matching Rules", UAX44-LM3; | ||
| # https://www.unicode.org/reports/tr44/). | ||
| name = name.lower().replace("_", "").replace("-", "").replace(" ", "") | ||
| name = "".join(ch for ch in name.lower() if ch not in " \t\n\r\f\v_-") |
Member
There was a problem hiding this comment.
This code is significantly slower than a sequence of replaces. The fastest method is to use translate() with predefined table created by str.maketrans().
serhiy-storchaka
left a comment
Member
There was a problem hiding this comment.
Also, no NEWS entry is needed. This is a fix of an unreleased feature.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Georgefifth
force-pushed
the
fix/re-property-whitespace
branch
from
August 28, 2026 23:21
8b94a7c to
0bfce66
Compare
Georgefifth
commented
Aug 28, 2026
Georgefifth
left a comment
Author
There was a problem hiding this comment.
All three addressed in 0bfce66:
- Double "and" — fixed, the comment now reads "case, whitespace, hyphens and underscores".
- translate() — the strip is now
name.lower().translate(_NON_SIGNIFICANT)with the table built once viastr.maketrans("", "", " \t\n\r\f\v_-")at module level. Measured on a 33-char name: ~1.4x faster than the generator expression. - NEWS — removed; it is a fix to an unreleased feature, as you said.
test_re passes on a locally built interpreter (169 tests, 3 skipped, all pre-existing skips).
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.

Problem
The docs (and the
_normalizecomment) promise that\p{...}property and value names are matched loosely — case, whitespace, hyphens and underscores are not significant (UAX #44, LM3). In practice only spaces were removed, so\p{L\tu}or\p{G\nC=Lu}raisedre.error: unknown property "L\ntu"while the space form worked. (3.16-only feature, so no compatibility concern.)Solution
_normalize()inLib/re/_properties.pynow drops all ASCII whitespace (\t\n\r\f\v), not just space; comment updated to match.Result
Added a regression loop over all six whitespace characters in
test_re.py::test_property_escapes; fulltest_repasses (169 tests) on a debug build, and the new assertions fail on the unpatched code. NEWS entry added.\p{...}names ignore only spaces, though the docs promise whitespace #156185