GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support regular expressions in `-W` and `PYTHONWARNINGS` · Issue #134716 · python/cpython

Support regular expressions in -W and PYTHONWARNINGS #134716

New issue
Copy link
New issue
Copy link
Closed
Closed
Support regular expressions in -W and PYTHONWARNINGS#134716
Copy link
Assignees
serhiy-storchaka
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@garyaviv
garyaviv
opened on May 26, 2025
Issue body actions

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

  • gh-134716: Support regular expressions in -W and PYTHONWARNINGS #138149

Activity

  1. garyaviv
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 26, 2025
  2. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on May 26, 2025
  3. picnixz commented on May 26, 2025

    @picnixz
    picnixz
    on May 26, 2025
    Member
    More actions

    The docs say:

    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)

  4. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 26, 2025
  5. picnixz
    changed the title [-]regular expressions in symbol PYTHONWARNINGS don't work[/-] [+]Support regular expressions in `-W` and `PYTHONWARNINGS`[/+] on May 26, 2025
  6. garyaviv commented on May 26, 2025

    @garyaviv
    garyaviv
    on May 26, 2025
    Author
    More actions

    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.

  7. serhiy-storchaka commented on May 30, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on May 30, 2025
    Member
    More actions

    See also #78805, #79101, #86438, #88028. There may be other duplicate issues.

    Reacted by Bénédikt Tran
  8. picnixz commented on May 30, 2025

    @picnixz
    picnixz
    on May 30, 2025
    Member
    More actions

    Arf, my bad. I'll triage them tomorrow.

  9. serhiy-storchaka commented on May 30, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on May 30, 2025
    Member
    More actions

    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.

  10. serhiy-storchaka
    self-assigned this
    on Aug 25, 2025
  11. serhiy-storchaka
    added a commit that references this issue on Aug 25, 2025

    pythongh-134716: Support regular expressions in -W and PYTHONWARNINGS

    dcb9cfd
  12. serhiy-storchaka commented on Aug 25, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 25, 2025
    Member
    More actions

    #138149 implements support of regular expressions. To differentiate them from literal strings, you must surround them by forward slashes.

    Using the original example:

    $ PYTHONWARNINGS='ignore:This.*deadlocks:DeprecationWarning' ./python -c 'import warnings; print(warnings.filters[0])'
    ('ignore', re.compile('This\\.\\*deadlocks', re.IGNORECASE), <class 'DeprecationWarning'>, None, 0)
    $ PYTHONWARNINGS='ignore:/This.*deadlocks/:DeprecationWarning' ./python -c 'import warnings; print(warnings.filters[0])'
    ('ignore', re.compile('This.*deadlocks', re.IGNORECASE), <class 'DeprecationWarning'>, None, 0)
  13. serhiy-storchaka commented on Sep 15, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Sep 15, 2025
    Member
    More actions

    Previous issues which were closed after changing the documentation:

    • -W option and PYTHONWARNINGS env variable does not accept module regexes #78805
    • PYTHONWARNINGS entries are escaped #79101
    • Warning filter message/module documentation is misleading #86438
    • warnings: -W option and PYTHONWARNINGS now use the message as a regex #88028
  14. serhiy-storchaka
    added a commit that references this issue on Sep 16, 2025

    gh-134716: Support regular expressions in -W and PYTHONWARNINGS (GH-1…

    cf9ef73
  15. serhiy-storchaka
    closed this as completedon Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @serhiy-storchaka
    serhiy-storchaka

Labels

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.