This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients serhiy.storchaka
Date 2019-12-15.18:43:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576435413.35.0.296920431157.issue39056@roundup.psfhosted.org>
In-reply-to
Content
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'

2. 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'

3. The re module is always imported is the -W option is used, even if this is not needed.
History
Date User Action Args
2019-12-15 18:43:33serhiy.storchakasetrecipients: + serhiy.storchaka
2019-12-15 18:43:33serhiy.storchakasetmessageid: <1576435413.35.0.296920431157.issue39056@roundup.psfhosted.org>
2019-12-15 18:43:32serhiy.storchakalinkissue39056 messages
2019-12-15 18:43:32serhiy.storchakacreate