Open
Description
Bug report
Bug description:
When the PYTHONWARNINGS message field contains a special character such as . or * it gets quoted as \. or \* so it looses it's regex meaning and never matches. I tested this in 3.8 and 3.13.
PYTHONWARNINGS='ignore:This.*deadlocks:DeprecationWarning' python -c 'import warnings; print(warnings.filters[0])'
yields:
('ignore', re.compile('This\\.\\*deadlocks', re.IGNORECASE), <class 'DeprecationWarning'>, None, 0)
(note the extra backslash is a result of the print statement, doing a repr.)
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Activity
picnixz commentedon May 26, 2025
The docs say:
So I don't think we're meant to support regexes when using
-W
andPYTHONWARNINGS
(but we can when we use the module directly)[-]regular expressions in symbol PYTHONWARNINGS don't work[/-][+]Support regular expressions in `-W` and `PYTHONWARNINGS`[/+]garyaviv commentedon May 26, 2025
Thank you for clarification.
My fault. The docs 3.10.7 indeed says -W and PYTHONWARNINGS is a literal string. Prior versions seem to lack this language:
serhiy-storchaka commentedon May 30, 2025
See also #78805, #79101, #86438, #88028. There may be other duplicate issues.
picnixz commentedon May 30, 2025
Arf, my bad. I'll triage them tomorrow.
serhiy-storchaka commentedon May 30, 2025
All of them were closed. AFAIK. only the documentation was updated.
But I had ideas on how to solve this problem differently, so we can leave this issue for that or reopen one of old issues if they contain more information.