"Local variable (defined in enclosing scope) referenced before assignment" wording is misleading
还没有人认领这个 Issue。
评估
调研方向
首先定位格式化 F823 诊断信息的代码,然后将其措辞与本 issue 中的示例以及 #315 中的相关示例进行比较。完成的标准是:消息明确说明内部名称遮蔽了外层作用域的名称,而不是说外层变量在赋值前被引用。
由索引模型根据 Issue 内容生成。
描述
def f():
x = None
def g():
# Programmer forgot to add `nonlocal` here.
if x is None:
x = "hello"
foo.py:5:12: F823 local variable 'x' (defined in enclosing scope on line 2) referenced before assignment
But it's not the variable defined on line 2 which is being referenced before assignment, it's the one defined on line 6. The programmer thinks they're using the one on line 2, and the message only reinforces their mistake.
Suggest rephrase to something like (shadowing name from line 2 in enclosing scope).
(There's a similar example in #315 where the enclosing scope was global.)
- 主要语言
- Python
- 星标
- 1.5k
- 派生
- 207
- 平均合并
- 4 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PyCQA/pyflakes 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 52/100
-
Use of await in a function that is not async should be shown as a syntax error by flake8可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 45/100
-
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
-
Library sweep logs an ERROR at start for the valkey instrumentor when valkey-py is not installed未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 85/100
JoahanMorales/upiixia-agentic-kit#99 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 85/100
NatLabRockies/openstudio-mcp#286 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100