From 90ff6bb91f81cdee5e457d1a939ed1110837ac0e Mon Sep 17 00:00:00 2001 From: CrackTC Date: Tue, 13 Jan 2026 22:19:27 +0800 Subject: [PATCH] fix(python): only create subscope for FunctionDefinition --- src/engine/analyzer/python/common/python-analyzer.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine/analyzer/python/common/python-analyzer.ts b/src/engine/analyzer/python/common/python-analyzer.ts index 427ad6df..4e3949ed 100644 --- a/src/engine/analyzer/python/common/python-analyzer.ts +++ b/src/engine/analyzer/python/common/python-analyzer.ts @@ -744,7 +744,11 @@ class PythonAnalyzer extends (Analyzer as any) { } else { scopeName = `` } - const block_scope = Scope.createSubScope(scopeName, scope, 'scope') + let block_scope = scope + if (node.parent?.type === 'FunctionDefinition') { + // 只对函数体内的块语句创建子作用域,python的其他块语句不创建子作用域 + block_scope = Scope.createSubScope(scopeName, scope, 'scope') + } node.body .filter((n: any) => needCompileFirst(n.type)) .forEach((s: any) => this.processInstruction(block_scope, s, state))