Message358439
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. |
|
Date |
User |
Action |
Args |
2019-12-15 18:43:33 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka |
2019-12-15 18:43:33 | serhiy.storchaka | set | messageid: <1576435413.35.0.296920431157.issue39056@roundup.psfhosted.org> |
2019-12-15 18:43:32 | serhiy.storchaka | link | issue39056 messages |
2019-12-15 18:43:32 | serhiy.storchaka | create | |
|