Shadowing and unshadowing a builtin makes pyflakes emit a F821
还没有人认领这个 Issue。
评估
调研方向
首先使用 pyflakes 或 flake8 运行提供的 shadowing 和 unshadowing 示例,然后将其与 linkcheck 示例进行比较。跟踪 del 附近对 undefined names 的处理,并添加一个回归测试,证明删除后对有效的 builtin 或 gettext 的使用不会发出 F821;该测试仍应捕获真正未定义的名称。
由索引模型根据 Issue 内容生成。
描述
Consider this silly code:
int = 42
del int
x = int('42')
print(x)
This is perfectly valid Python: if you run it, it'll print 42.
flake8 emits a F821: undefined name 'int' on the penultimate line. I think it's because of the del int.
For a real-world example of this situation, consider a project that uses gettext and installs _ in builtins, but doesn't do that early enough to be available at import time of every module. Here's how linkchecker copes with that situation:
_ = lambda x: x
Fields = dict(
realurl=_("Real URL"),
cachekey=_("Cache key"),
...
level=_("Level"),
modified=_("Modified"),
)
del _
and this then causes flake8 to complain about _() being used elsewhere in the file:
./linkcheck/logger/__init__.py:278:19: F821 undefined name '_'
./linkcheck/logger/__init__.py:340:16: F821 undefined name '_'
./linkcheck/logger/__init__.py:377:22: F821 undefined name '_'
./linkcheck/logger/__init__.py:380:22: F821 undefined name '_'
./linkcheck/logger/__init__.py:382:22: F821 undefined name '_'
./linkcheck/logger/__init__.py:390:22: F821 undefined name '_'
flake8 --version reports
3.8.2 (flake8_2020: 1.6.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.8.2 on Linux
- 主要语言
- Python
- 星标
- 1.5k
- 派生
- 205
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 5
环境准备
这个项目没有提供开发容器、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
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
micropython/micropython#19906 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
FinanceFlash/unvibecode#597 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
TomAnthony/YourOwnWeigh#21 ·
维护者通常 1 天内回复
-
[BUG]: Compliance rules never see Unity Catalog views as views可能已有人在做 @wagnercsantos 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
databrickslabs/ontos#1348 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复