Bug description:
A FutureWarning raised while parsing a nested set inside a set-operation operand is attributed to a frame inside the re package rather than to the caller, and lands further away the deeper the nesting. _parse_operand() in Lib/re/_parser.py adds two frames but advances nested by one, so the stacklevel is one short.
import re, warnings
for pattern in [r'[[b]]', r'[a--[[b]]]']:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
re.compile(pattern)
print(pattern, '->', w[0].filename == __file__)
[[b]] -> True
[a--[[b]]] -> False
Expected: True for both. test_set_operations in Lib/test/test_re.py already asserts w.filename == __file__ for the top-level spelling. Because warning filters and the default duplicate suppression key on the reported location, -W 'error::FutureWarning:__main__' raises on the first pattern and misses the second.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug description:
A
FutureWarningraised while parsing a nested set inside a set-operation operand is attributed to a frame inside therepackage rather than to the caller, and lands further away the deeper the nesting._parse_operand()inLib/re/_parser.pyadds two frames but advancesnestedby one, so thestacklevelis one short.Expected:
Truefor both.test_set_operationsinLib/test/test_re.pyalready assertsw.filename == __file__for the top-level spelling. Because warning filters and the default duplicate suppression key on the reported location,-W 'error::FutureWarning:__main__'raises on the first pattern and misses the second.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs