fix(vast): FunctionDef 槽位补 Extern/Export,修 __slots__ 回归 AttributeError
_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。
This commit is contained in:
1 parent
68d180e718
commit
043c65ee52
1 file changed
+5
-2
+5
-2
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user