Conversation
主要修复: 1. 增强变量绑定的处理,避免对变量重新赋值报错 2. 完善各种 Python 语法结构中的变量绑定支持: - for/async for 循环变量(包括解包和星号表达式) - 列表/集合/字典/生成器推导式中的目标变量 - with/async with 语句的 as 别名 - except 处理器的 as 别名 - 海象运算符 (:=) 的目标变量 3. 修复推导式作用域隔离的处理 4. 增强 audit() 方法以支持直接传入 AST 树 新增功能: - 添加了 GitHub Actions 工作流 auditor-selftest.yml 用于在 CI 中自动运行 ASTAuditor 对项目自身代码的审计 - 添加了全面的测试用例 test_issue_39_scope_binding.py 覆盖所有变量绑定场景的验证 技术改进: - 使用栈来跟踪作用域路径,提升作用域管理的准确性 - 通过 _register_targets() 统一处理各种赋值目标 - 为推导式创建临时作用域,正确模拟 Python 的作用域规则 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
注意事项在运行测试套件时,我发现了一些与 相关的测试失败,这些失败与本 PR 的修改无关,但值得下一个开发者注意: 失败的测试
建议这些测试失败可能指向 中以下几个方面需要改进:
这些问题应该在单独的 issue 中跟踪和修复,以保持关注点分离。 |
Owner
Author
注意事项在运行测试套件时,我发现了一些与 失败的测试
建议这些测试失败可能指向
这些问题应该在单独的 issue 中跟踪和修复,以保持关注点分离。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
解决了 Issue #39 中报告的
ASTAuditor对多种合法 Python 语法结构产生"未定义名称"误报的问题。主要修复了以下场景的误报:
for,async for, comprehensions)with,async with)except ... as ...):=, PEP 572)技术实现
1. 通用的
_register_targets助手函数2. 扩展 SymbolTableBuilder
为以下 AST 节点类型添加了 visitor 方法:
visit_For/visit_AsyncForvisit_With/visit_AsyncWithvisit_ExceptHandlervisit_ListComp/visit_SetComp/visit_DictComp/visit_GeneratorExpvisit_NamedExpr3. 增强的 ReferenceValidator
4. 改进的重复定义检测
测试
test_issue_39_scope_binding.py),包含 16 个测试用例CI 增强
添加了
auditor-selftest.yml工作流:性能
测试计划
pytest tests/test_issue_39_scope_binding.py -vpytest tests/unit/ -vCloses #39
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com