From 043c65ee5286554963607be58d0ecf1d43a65b42 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 18 Aug 2026 05:12:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(vast):=20FunctionDef=20=E6=A7=BD=E4=BD=8D?= =?UTF-8?q?=E8=A1=A5=20Extern/Export=EF=BC=8C=E4=BF=AE=20=5F=5Fslots=5F=5F?= =?UTF-8?q?=20=E5=9B=9E=E5=BD=92=20AttributeError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _ParseExternDef/_ParseExportDef 设置 node.Extern/node.Export(动态属性), __slots__ 类无 __dict__ 导致 AttributeError: 'FunctionDef' object has no attribute 'Extern'。FunctionDef/AsyncFunctionDef 的 attrs 补 Extern/Export(_FUNC_ATTRS),槽位随之包含;unparse 用 getattr 读取兼容。 extern/export 冒烟 + vast 差分 51/53 0 FAIL。 --- lib/vast/Nodes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/vast/Nodes.py b/lib/vast/Nodes.py index 035dd16..028b65f 100644 --- a/lib/vast/Nodes.py +++ b/lib/vast/Nodes.py @@ -49,6 +49,9 @@ class AST: # ============================================================================= _POS_ATTRS: tuple[str, ...] = ('lineno', 'col_offset', 'end_lineno', 'end_col_offset') +# extern/export 软关键字标记(_ParseExternDef/_ParseExportDef 写入,unparse 还原)。 +# __slots__ 类无 __dict__,必须纳入槽位,否则 node.Extern = True 抛 AttributeError。 +_FUNC_ATTRS: tuple[str, ...] = _POS_ATTRS + ('Extern', 'Export') _NODE_DEFS: dict[str, tuple[tuple[str, ...], tuple[str, ...]]] = { # ---- 模块/交互/表达式顶层 ---- @@ -59,8 +62,8 @@ _NODE_DEFS: dict[str, tuple[tuple[str, ...], tuple[str, ...]]] = { 'Suite': ((), ()), # ---- 语句 ---- - 'FunctionDef': (('name', 'args', 'body', 'decorator_list', 'returns', 'type_comment', 'type_params'), _POS_ATTRS), - 'AsyncFunctionDef': (('name', 'args', 'body', 'decorator_list', 'returns', 'type_comment', 'type_params'), _POS_ATTRS), + 'FunctionDef': (('name', 'args', 'body', 'decorator_list', 'returns', 'type_comment', 'type_params'), _FUNC_ATTRS), + 'AsyncFunctionDef': (('name', 'args', 'body', 'decorator_list', 'returns', 'type_comment', 'type_params'), _FUNC_ATTRS), 'ClassDef': (('name', 'bases', 'keywords', 'body', 'decorator_list', 'type_params'), _POS_ATTRS), 'Return': (('value',), _POS_ATTRS), 'Delete': (('targets',), _POS_ATTRS),