Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with handling the -W option #83237

Closed
serhiy-storchaka opened this issue Dec 15, 2019 · 4 comments
Closed

Issues with handling the -W option #83237

serhiy-storchaka opened this issue Dec 15, 2019 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 39056
Nosy @serhiy-storchaka, @miss-islington
PRs
  • bpo-39056: Fix handling invalid warning category in the -W option. #17618
  • [3.8] bpo-39056: Fix handling invalid warning category in the -W option. (GH-17618) #17831
  • [3.7] bpo-39056: Fix handling invalid warning category in the -W option. (GH-17618) #17832
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-01-05.13:33:25.031>
    created_at = <Date 2019-12-15.18:43:32.999>
    labels = ['3.7', '3.8', 'type-bug', 'library', '3.9']
    title = 'Issues with handling the -W option'
    updated_at = <Date 2020-01-05.13:33:25.030>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-01-05.13:33:25.030>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-05.13:33:25.031>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2019-12-15.18:43:32.999>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39056
    keywords = ['patch']
    message_count = 4.0
    messages = ['358439', '359333', '359338', '359339']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'miss-islington']
    pr_nums = ['17618', '17831', '17832']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39056'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    There are some issues with handling the -W option:

    1. A traceback is printed for some invalid category names.
    $ ./python -Wignore::0
    'import warnings' failed; traceback:
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 542, in <module>
        _processoptions(sys.warnoptions)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 208, in _processoptions
        _setoption(arg)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 224, in _setoption
        category = _getcategory(category)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 271, in _getcategory
        if not issubclass(cat, Warning):
    TypeError: issubclass() arg 1 must be a class
    
    $ ./python -Wignore::0a 
    'import warnings' failed; traceback:
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 542, in <module>
        _processoptions(sys.warnoptions)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 208, in _processoptions
        _setoption(arg)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 224, in _setoption
        category = _getcategory(category)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 256, in _getcategory
        cat = eval(category)
      File "<string>", line 1
        0a
         ^
    SyntaxError: unexpected EOF while parsing
    
    $ ./python -Wignore::=
    'import warnings' failed; traceback:
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 542, in <module>
        _processoptions(sys.warnoptions)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 208, in _processoptions
        _setoption(arg)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 224, in _setoption
        category = _getcategory(category)
      File "/home/serhiy/py/cpython/Lib/warnings.py", line 264, in _getcategory
        m = __import__(module, None, None, [klass])
    ValueError: Empty module name

    In normal case Python just complains:

    $ ./python -Wignore::unknown
    Invalid -W option ignored: unknown warning category: 'unknown'
    1. For non-ascii warning names Python complains about a module and strips the last character:
    $ ./python -Wignore::Wärning
    Invalid -W option ignored: invalid module name: 'Wärnin'
    1. The re module is always imported is the -W option is used, even if this is not needed.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 15, 2019
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 41ec17e by Serhiy Storchaka in branch 'master':
    bpo-39056: Fix handling invalid warning category in the -W option. (GH-17618)
    41ec17e

    @miss-islington
    Copy link
    Contributor

    New changeset e1caa49 by Miss Islington (bot) in branch '3.8':
    bpo-39056: Fix handling invalid warning category in the -W option. (GH-17618)
    e1caa49

    @miss-islington
    Copy link
    Contributor

    New changeset 43fbc70 by Miss Islington (bot) in branch '3.7':
    bpo-39056: Fix handling invalid warning category in the -W option. (GH-17618)
    43fbc70

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants