Skip to content

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

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-re-nested-operand-warning-stacklevel
Open

gh-156187: Fix the warning stacklevel inside a nested set operand#156188
fedonman wants to merge 1 commit 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.
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.

2 participants