fix(len): 泛型特化缺方法时回退裸模板类

len(list[AST*]) 在特化方法尚未生成时回退查找 list.__len__,避免误报没有 __len__ 方法。
This commit is contained in:
TermiNexus committed 2026-10-18 16:53:35 +08:00
1 parent da13e7b405
commit 43cedbd3b7
1 file changed
+6
+6
View File
@@ -177,6 +177,12 @@ class ExprUtils:
FullMethodName: str = f'{ClassName}.{op_name}'
if not Gen._has_function(FullMethodName):
FullMethodName = f'{ClassName}.{op_name}__'
if not Gen._has_function(FullMethodName) and '[' in ClassName:
# 泛型特化方法尚未生成时,回退到裸模板类的方法(如 list.__len__)
_BareClass: str = ClassName.split('[', 1)[0]
FullMethodName = f'{_BareClass}.{op_name}'
if not Gen._has_function(FullMethodName):
FullMethodName = f'{_BareClass}.{op_name}__'
if not Gen._has_function(FullMethodName):
# 多继承:沿 MRO 祖先链查找 dunder 方法(先声明父类优先,与 VPC 一致)
for anc in Gen._get_mro_chain(ClassName)[1:]: