Skip to content

gh-95555: Fix a stale comment about negating \P in a character class - #156490

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-test-re-negated-property-comment
Open

gh-95555: Fix a stale comment about negating \P in a character class#156490
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-test-re-negated-property-comment

Conversation

@fedonman

@fedonman fedonman commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

The comment above the [\P{Alphabetic}] assertion in test_property_escapes still says that, unlike an engine category, \P of a multi-range property cannot be negated inside a character class. GH-152245 lifted that restriction, and the same test now asserts fifty lines below that [\P{ASCII}], [\P{ASCII}abc] and [^\P{ASCII}] all match. The comment now states the distinction that does remain, which is how the member is compiled rather than whether it is allowed:

>>> re._parser.parse(r'[\P{Alphabetic}x]')
[(IN, [(CATEGORY, CATEGORY_NOT_ALPHA), (LITERAL, 120)])]
>>> re._parser.parse(r'[\P{ASCII}x]')
[(BRANCH, (None, [[(LITERAL, 120)], [(IN, [(NEGATE, None), (RANGE, (0, 127))])]]))]
test_property_escapes (test.test_re.ReTests.test_property_escapes) ... ok
Total tests: run=1 (filtered)
Result: SUCCESS

Comment-only change in a test file, so there is no news entry.

…class

pythonGH-152245 lifted the restriction that a negated multi-range property
could not appear inside a character class, and added assertions in
test_property_escapes showing that [\P{ASCII}] and friends now match.
It left in place an earlier comment in the same test saying that,
unlike an engine category, \P of a multi-range property cannot be
negated inside a character class.

The distinction that remains is how the member is compiled, not
whether it is allowed: an engine category joins the set directly as a
CATEGORY, while a multi-range \P is alternated in as a separate branch.
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant