Repository navigation
codeop: 3.8.5 regression, warnings.simplefilter('error', SyntaxWarning) does not raise. #85692
Description
Activity
assuming
$ cat foo.py import warnings from codeop import compile_commandwarnings.simplefilter('error', SyntaxWarning) res = compile_command('1 is 1\n', symbol='exec') print('Res', res)
On 3.8.0...3.8.4 this correctly raises a SyntaxError:
python foo.py Traceback (most recent call last): File "foo.py", line 5, in <module> res = compile_command('1 is 1\n', symbol='exec') File "/Users/bussonniermatthias/miniconda3/envs/38/lib/python3.8/codeop.py", line 122, in compile_command return _maybe_compile(_compile, source, filename, symbol) File "/Users/bussonniermatthias/miniconda3/envs/38/lib/python3.8/codeop.py", line 99, in _maybe_compile raise err1 File "/Users/bussonniermatthias/miniconda3/envs/38/lib/python3.8/codeop.py", line 87, in _maybe_compile code1 = compiler(source + "\n", filename, symbol) File "/Users/bussonniermatthias/miniconda3/envs/38/lib/python3.8/codeop.py", line 102, in _compile return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT) File "<input>", line 1 SyntaxError: "is" with a literal. Did you mean "=="?
But will silently return None on 3.8.5
$ python foo.py Res None
- added3.8 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Aug 10, 2020 seem to affect 3.8.4 as well.
Potentially due to
- changed the title
[-]3.8.5 regression, warnings.simplefilter('error', SyntaxWarning) does not raise.[/-][+]codeop: 3.8.5 regression, warnings.simplefilter('error', SyntaxWarning) does not raise.[/+]on Aug 11, 2020 I proposed a fix: PR 21838. Would you mind to review it?
6 remaining items
This 'fix' introduces another regression by undoing the previous fix in bpo-40807 of emitting DeprecationWarning (for '\e', for instance) just once instead of thrice.
I suspect that the example of Matthias would fail in a debug build (with DeprecationWarnings on) for DeprecationWarning also.
PR-21848 removes the limitation of the first fix to SyntaxWarning and includes DeprecationWarning in the test for single emission.
The commit 369a1cb introduces a change in environment. I haven't checked the other PR though to see if this is fixed.
./python.exe -m test --fail-env-changed test_codeop -m test_warning
0:00:00 load avg: 2.30 Run tests sequentially
0:00:00 load avg: 2.30 [1/1] test_codeop
Warning -- warnings.filters was modified by test_codeop
Before: (4331716096, [('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)], [('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)])
After: (4331716096, [('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)], [('error', None, <class 'SyntaxWarning'>, None, 0), ('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)])
test_codeop failed (env changed)== Tests result: ENV CHANGED ==
1 test altered the execution environment:
test_codeopTotal duration: 38 ms
Tests result: ENV CHANGEDOn an unrelated note the test passes with verbose mode though fail-env-changed flag is passed.
./python.exe -m test --fail-env-changed test_codeop -m test_warning -vvv
== CPython 3.10.0a0 (heads/master:c51db0ea40d, Aug 13 2020, 15:47:27) [Clang 10.0.1 (clang-1001.0.46.4)]
== macOS-10.14.6-x86_64-i386-64bit little-endian
== cwd: /Users/kasingar/stuff/python/cpython/build/test_python_29945æ
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
0:00:00 load avg: 1.53 Run tests sequentially
0:00:00 load avg: 1.53 [1/1] test_codeop
test_warning (test.test_codeop.CodeopTests) ... ok----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
== Tests result: SUCCESS ==
1 test OK.
Total duration: 58 ms
Tests result: SUCCESS
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:
bugs.python.org fields: