Misleading SyntaxError: cannot use assignment expressions with lambda
未关闭
还没有人认领这个 Issue。
interpreter-core
topic-parser
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Python 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> lambda x: foo := 2
File "<stdin>", line 1
lambda x: foo := 2
^^^^^^^^^^^^^
SyntaxError: cannot use assignment expressions with lambda
>>> lambda x: (foo := 2)
<function <lambda> at 0x00000229CC40E0C0>
IIRC, until today I believed that you could never use an assignment expression in a lambda. I was disabused of this notion only by reading PEP 572 itself. I believe the SyntaxError should ideally read something along the lines of "cannot use unparenthesized assignment expressions with lambda".
I wasn't sure to what category to file this under exactly, sorry if I chose wrong.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 CPython 中搜索确切的诊断信息 "cannot use assignment expressions with lambda",并以 PEP 572 为背景,检查相关的 parser 或 compiler 处理。复现报告中的两个 lambda 示例;完成标准是:不带括号的形式报告更精确的限制,而带括号的形式继续正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100