Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue35169

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:Improve error messages for assignment
Type:enhancementStage:resolved
Components:Interpreter CoreVersions:Python 3.8
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: benjamin.peterson, brett.cannon, serhiy.storchaka, yselivanov
Priority:normalKeywords:patch

Created on2018-11-05 19:17 byserhiy.storchaka, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 10342mergedserhiy.storchaka,2018-11-05 19:21
Messages (3)
msg329313 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-11-05 19:17
This is a follow up ofissue34641.>>> f(lambda x: x = 1)  File "<stdin>", line 1SyntaxError: lambda cannot contain assignment>>> f(x.y = 1)  File "<stdin>", line 1SyntaxError: keyword can't be an expressionThe error message "keyword can't be an expression" still looks confusing to me. This is because the term "keyword" is ambiguous. Usually it means reserved identifier like "if" or "def". Some keywords, like "None" and "True" can be expressions. Perhaps "keyword name can't be an expression" would be better.But I think that in these cases it is most likely that "=" was used instead of "==". And it would be better to generalize the error message for lambdas and point on a possible typo.>>> f(x.y = 1)  File "<stdin>", line 1SyntaxError: expression cannot contain assignment, perhaps you meant "=="?The proposed PR changes this error message. It makes also an error message for forbidden assignment more concrete: "cannot assign to __debug__" instead of "assignment to keyword" (the latter is actually incorrect, because __debug__ is not true keyword in tokenizer). This restores Python 2 error messages. Improved also other error messages for forbidden assigning: dict and set displays, f-string expressions are not literals.
msg330056 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-11-18 17:30
Benjamin, could you please take a look at this?
msg330138 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-11-20 17:27
New changeset97f1efb6062188645a470daaa91e3669d739c75f by Serhiy Storchaka in branch 'master':bpo-35169: Improve error messages for forbidden assignments. (GH-10342)https://github.com/python/cpython/commit/97f1efb6062188645a470daaa91e3669d739c75f
History
DateUserActionArgs
2022-04-11 14:59:07adminsetgithub: 79350
2018-11-20 18:07:05serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-11-20 17:27:19serhiy.storchakasetmessages: +msg330138
2018-11-18 17:30:57serhiy.storchakasetmessages: +msg330056
2018-11-06 18:42:14gvanrossumsetnosy: -gvanrossum
2018-11-05 19:21:18serhiy.storchakasetkeywords: +patch
stage: patch review
pull_requests: +pull_request9645
2018-11-05 19:17:32serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp