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.
In -W and PYTHONWARNINGS, message is a literal string that the start of the warning message must contain (case-insensitively), ignoring any whitespace at the start or end of message
So I don't think we're meant to support regexes when using -W and PYTHONWARNINGS (but we can when we use the module directly)
changed the title [-]regular expressions in symbol PYTHONWARNINGS don't work[/-][+]Support regular expressions in `-W` and `PYTHONWARNINGS`[/+]on 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:
The warnings filter is initialized by -W options passed to the Python interpreter command line and the PYTHONWARNINGS environment variable.
<snip>
Individual warnings filters are specified as a sequence of fields separated by colons:
action:message:category:module:line
The meaning of each of these fields is as described in The Warnings Filter.
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.
Activity
picnixz commented on May 26, 2025
The docs say:
So I don't think we're meant to support regexes when using -W and PYTHONWARNINGS (but we can when we use the module directly)
garyaviv commented on 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 commented on May 30, 2025
See also #78805, #79101, #86438, #88028. There may be other duplicate issues.
picnixz commented on May 30, 2025
Arf, my bad. I'll triage them tomorrow.
serhiy-storchaka commented on 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.
pythongh-134716: Support regular expressions in -W and PYTHONWARNINGS
serhiy-storchaka commented on Aug 25, 2025
#138149 implements support of regular expressions. To differentiate them from literal strings, you must surround them by forward slashes.
Using the original example:
serhiy-storchaka commented on Sep 15, 2025
Previous issues which were closed after changing the documentation:
gh-134716: Support regular expressions in -W and PYTHONWARNINGS (GH-1…