Conversation
修复内容: 1. ✅ 循环依赖检测:通过解析 import_alias 的传递依赖,确保拓扑排序能准确检测循环 2. ✅ 属性链完整性:保持属性调用链(如 a.b.c, super().__init__)的完整结构 3. ✅ 命名冲突策略:所有导入别名都添加后缀,用户定义的符号保持原名 4. ✅ 别名重命名规则:静态导入使用 __mod 后缀,运行时导入使用 __rt 后缀 主要修改: - 添加 _fix_import_alias_dependencies 方法修复循环导入时的依赖关系缺失 - 改进 topological_sort 方法,解析 import_alias 的传递依赖 - 修改 generate_name_mappings,所有 import_alias 符号都添加适当后缀 - 处理运行时导入,不再将 try...except ImportError 块保留为初始化语句 - 添加运行时导入的输出逻辑,确保它们被正确重命名 测试: - 新增 test_issue_41_fixes.py 完整测试所有修复 - 所有相关测试套件通过 Fixes #41 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- 在所有访问 symbol.scope.module_path 的地方添加 None 检查 - 对于没有 scope 的符号,使用默认值或跳过处理 - 确保代码能够处理外部模块符号(scope=None)的情况
主要修复: 1. 修复 AttributeError: 'NoneType' object has no attribute 'module_path' - 在访问 symbol.scope.module_path 前添加 None 检查 - 影响多个方法:_collect_and_reinject_imports 等 2. 修复重复导入问题(如 cp__mod 被导入两次) - 在 _process_imports 中添加 seen_aliases 集合进行去重 - 避免相同的别名被多次定义 3. 修复 ASTAuditor 不识别 *args 和 **kwargs 参数的问题 - 在 SymbolTableBuilder.visit_FunctionDef 中添加 vararg 和 kwarg 处理 - 同样更新了 visit_AsyncFunctionDef 这些修复解决了在处理 sota.py 等复杂脚本时的崩溃和错误。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
问题分析
Issue #41 指出了
advanced_merge.py的四个核心架构缺陷:循环依赖检测失效:由于 import_alias 符号的依赖关系在循环导入时可能缺失,导致拓扑排序无法检测到实际存在的循环依赖。
属性调用链错误截断:属性链(如
a.b.c)和super().__init__()调用本身没有问题,测试显示此功能正常工作。符号命名冲突策略失败:原实现只在有冲突时重命名,没有统一为所有导入别名添加后缀。
模块别名重命名混乱:运行时导入(try...except ImportError 块中的导入)没有被正确处理和重命名。
解决方案
1. 循环依赖检测修复
_fix_import_alias_dependencies方法,在所有模块分析完成后修复 import_alias 的依赖关系topological_sort方法,添加resolve_transitive_deps函数解析 import_alias 的传递依赖2. 属性链完整性(已正常)
3. 命名冲突策略重构
generate_name_mappings方法,对所有 import_alias 符号都添加后缀,而不只是有冲突的4. 别名重命名规则规范化
__mod后缀__rt后缀Test plan
test_issue_41_fixes.py完整测试所有修复test_circular_dependency_detection.py)test_advanced_merger_fixes.py)test_auditor_catches_bad_merge.py)test_full_merge_workflow.py)Fixes #41
🤖 Generated with Claude Code