Skip to content

Support regular expressions in -W and PYTHONWARNINGS #134716

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

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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