
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2018-10-20 07:24 byserhiy.storchaka, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 9999 | merged | serhiy.storchaka,2018-10-20 07:29 | |
| Messages (2) | |||
|---|---|---|---|
| msg328130 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2018-10-20 07:24 | |
SyntaxError contains more useful information than SyntaxWarning, and SyntaxError is special cased in tracebacks for better reporting. When SyntaxWarning is raised as an exception, the error report doesn't contain information about the source. It is hard to find the source of a SyntaxWarning. Currently:$ ./python syntaxwarning.py syntaxwarning.py:1: SyntaxWarning: assertion is always true, perhaps remove parentheses? x = 1; assert (x, "msg")$ ./python -We syntaxwarning.py SyntaxWarning: assertion is always true, perhaps remove parentheses?$ ./python -m syntaxwarning/home/serhiy/py/cpython3.7/syntaxwarning.py:1: SyntaxWarning: assertion is always true, perhaps remove parentheses? x = 1; assert (x, "msg")$ ./python -We -m syntaxwarningTraceback (most recent call last): File "/home/serhiy/py/cpython3.7/Lib/runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/home/serhiy/py/cpython3.7/Lib/runpy.py", line 153, in _get_module_details code = loader.get_code(mod_name) File "<frozen importlib._bootstrap_external>", line 860, in get_code File "<frozen importlib._bootstrap_external>", line 791, in source_to_code File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedSyntaxWarning: assertion is always true, perhaps remove parentheses?The proposed PR replaces SyntaxWarning with a SyntaxError if the former was raised as an exception:$ ./python -We syntaxwarning.py File "syntaxwarning.py", line 1 x = 1; assert (x, "msg") ^SyntaxError: assertion is always true, perhaps remove parentheses?$ ./python -We -m syntaxwarningTraceback (most recent call last): File "/home/serhiy/py/cpython/Lib/runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/home/serhiy/py/cpython/Lib/runpy.py", line 153, in _get_module_details code = loader.get_code(mod_name) File "<frozen importlib._bootstrap_external>", line 909, in get_code File "<frozen importlib._bootstrap_external>", line 839, in source_to_code File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/serhiy/py/cpython/syntaxwarning.py", line 1 x = 1; assert (x, "msg") ^SyntaxError: assertion is always true, perhaps remove parentheses?Similar replacement is already performed for warnings raised for unrecognized escape sequences at parsing time (seeissue32912). | |||
| msg328192 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2018-10-21 07:09 | |
New changesetd31e7730cd5d74efbd7320751dacd51d09cc415d by Serhiy Storchaka in branch 'master':bpo-35029: Replace the SyntaxWarning exception with a SyntaxError. (GH-9999)https://github.com/python/cpython/commit/d31e7730cd5d74efbd7320751dacd51d09cc415d | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:07 | admin | set | github: 79210 |
| 2018-10-21 07:28:51 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2018-10-21 07:09:43 | serhiy.storchaka | set | messages: +msg328192 |
| 2018-10-20 07:29:14 | serhiy.storchaka | set | keywords: +patch stage: patch review pull_requests: +pull_request9341 |
| 2018-10-20 07:24:03 | serhiy.storchaka | create | |