Skip to content

Support regular expressions in -W and PYTHONWARNINGS #134716

@garyaviv

Description

@garyaviv

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

Linked PRs

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions