Skip to content

gh-156187: Fix the warning stacklevel inside a nested set operand - #156188

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
fedonman:fix-re-nested-operand-warning-stacklevel
Sep 4, 2026
Merged

gh-156187: Fix the warning stacklevel inside a nested set operand#156188
serhiy-storchaka merged 3 commits into
python:mainfrom
fedonman:fix-re-nested-operand-warning-stacklevel

Conversation

@fedonman

@fedonman fedonman commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

_parse_operand() now passes nested + 2 to the inner _parse_charset(), matching the two frames the nested-operand path adds, so a FutureWarning raised inside a nested set operand is reported against the caller at every depth. test_set_operations pins the reported file for the nested-set and the ~~ spelling.

$ ./python -m test test_re -v -m test_set_operations
test_set_operations (test.test_re.ReTests.test_set_operations) ... ok
Total tests: run=1 (filtered)
Result: SUCCESS
$ ./python -m test test_re
Total tests: run=169 skipped=3
Result: SUCCESS

No news entry: set operations in character classes are new in 3.16 and have not shipped, so this folds into the gh-152100 entry.

_parse_charset() derives the stacklevel of its FutureWarning from
nested, and the nested-operand path inserts two frames, _parse_operand()
and the inner _parse_charset(), while advancing nested by one.  The
warning was therefore reported against a frame inside the re package
instead of the caller, and further off the deeper the nesting.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This is a main-only regression.

LGTM. I only have few style suggestions for tests.

Comment thread Lib/test/test_re.py Outdated
Comment thread Lib/test/test_re.py Outdated
fedonman and others added 2 commits September 4, 2026 19:23
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@fedonman

fedonman commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @serhiy-storchaka I committed your suggestions.

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) September 4, 2026 16:34
@serhiy-storchaka
serhiy-storchaka merged commit 3a7a22b into python:main Sep 4, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants