Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue35029

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Convert SyntaxWarning exception raised at code generation time to a SyntaxError
Type:enhancementStage:resolved
Components:Interpreter CoreVersions:Python 3.8
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: serhiy.storchaka
Priority:normalKeywords:patch

Created on2018-10-20 07:24 byserhiy.storchaka, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 9999mergedserhiy.storchaka,2018-10-20 07:29
Messages (2)
msg328130 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)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)*(Python committer)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
DateUserActionArgs
2022-04-11 14:59:07adminsetgithub: 79210
2018-10-21 07:28:51serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-21 07:09:43serhiy.storchakasetmessages: +msg328192
2018-10-20 07:29:14serhiy.storchakasetkeywords: +patch
stage: patch review
pull_requests: +pull_request9341
2018-10-20 07:24:03serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp