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