From e5af28fa93b49cae5ddcea4c483b1804512f1ac1 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 17 Aug 2026 20:07:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(imports):=20NoneType=20=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=9D=99=E9=BB=98=20+=20struct=5Fbody=20=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=EF=BC=8C=E5=87=8F=E5=B0=91=20WARN=20=E5=B9=B2=E6=89=B0?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 编译大量输出 "HandlesImports: 忽略异常 'NoneType' object has no attribute 'endswith'":注解/类型解析回退路径对 None 参与运算(数据缺失属正常兜底)——每文件每符号都打 WARN 淹没关键信息。 - 783/1166/1264 三处 except:AttributeError+NoneType 时静默不 WARN,其他异常保留 - 两处 is_packed 判断补 struct_body is not None 防护(源头防 None.startswith/endswith) --- lib/core/Handles/HandlesImports.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/core/Handles/HandlesImports.py b/lib/core/Handles/HandlesImports.py index b341a0a..57bf388 100644 --- a/lib/core/Handles/HandlesImports.py +++ b/lib/core/Handles/HandlesImports.py @@ -777,10 +777,12 @@ class ImportHandle(BaseHandle): self._LoadModuleDeclarationsFromFile(sha1_pyi, Gen, module_name=alias.name, register_module_name=register_module_name, reexport_package=module_name) has_functions_or_classes = True except Exception as e: - if module_name == 'pyzlib': - node_type = type(node).__name__ - name = getattr(node, 'name', getattr(node, 'attr', '?')) - _vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) + # NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多) + if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)): + if module_name == 'pyzlib': + node_type = type(node).__name__ + name = getattr(node, 'name', getattr(node, 'attr', '?')) + _vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) continue if not has_functions_or_classes and module_name: self._LoadDeclarationsFromStubLlvm(module_name, Gen) @@ -1163,7 +1165,10 @@ class ImportHandle(BaseHandle): ReturnTypeInfo.BaseType = t.CInt() IsPtr = ReturnTypeInfo.IsPtr except Exception as e: # 回退:返回类型解析失败时使用默认 CInt - _vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) + # NoneType 异常(如对 None 调 endswith)是数据缺失的正常兜底场景, + # 静默不输出 WARN(干扰太多);其他异常保留提示。 + if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)): + _vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) ReturnTypeInfo = CTypeInfo() ReturnTypeInfo.BaseType = t.CInt() else: @@ -1261,7 +1266,9 @@ class ImportHandle(BaseHandle): ParamTypeInfo.PtrCount = max(ParamTypeInfo.PtrCount, 1) ParamType = Gen._ctype_to_llvm(ParamTypeInfo) except Exception as e: # 回退:参数类型解析失败时使用默认 i32 - _vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) + # NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多) + if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)): + _vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) ParamType = ir.IntType(32) if isinstance(ParamType, ir.VoidType) or (isinstance(ParamType, ir.PointerType) and isinstance(ParamType.pointee, ir.VoidType)): AnnName = None @@ -2109,7 +2116,7 @@ class ImportHandle(BaseHandle): if len(parts[0]) == 16 and all(c in '0123456789abcdef' for c in parts[0]): actual_sha1 = parts[0] - is_packed = struct_body.startswith('<{') and struct_body.endswith('}>') + is_packed = struct_body is not None and struct_body.startswith('<{') and struct_body.endswith('}>') if struct_body and struct_body != 'opaque': elem_types = [] if is_packed: @@ -2461,7 +2468,7 @@ class ImportHandle(BaseHandle): struct_body = struct_def_match.group(3).strip() if struct_body and struct_body != 'opaque': elem_types = [] - is_packed = struct_body.startswith('<{') and struct_body.endswith('}>') + is_packed = struct_body is not None and struct_body.startswith('<{') and struct_body.endswith('}>') if is_packed: inner = struct_body[2:-1].strip() else: