[New-bugs-announce] [issue39056] Issues with handling the -W option
Serhiy Storchaka
report at bugs.python.org
Sun Dec 15 13:43:33 EST 2019
New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:
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.
----------
components: Library (Lib)
messages: 358439
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Issues with handling the -W option
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39056>
_______________________________________
More information about the New-bugs-announce
mailing list