Closed
[Bug-Report|缺陷反馈]:【易用性】pypto.assemble 的 @overload 签名仅用于文档,运行时零校验,API 误用时报内部解包错误,且报错信息模糊无法指导定位 #3274
liuxiaoxiao11Add on Sep 9Closed at Sep 11
Sep 9 Added label: bug-report
袁野
Sep 9 Comments:
Sep 9 Comments:
@seu_chang 请关注处理下,谢谢


Sep 9 Associated pull request
Sep 9 Assign HuYiSheng01 as responsible person
Sep 11 Associated pull request
Sep 11 Close issue
Sep 11 Added label: resolved
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Describe the current behavior / 问题描述 (Mandatory / 必填)
pypto.assemble 声明了两套 @overload 签名(operation.py:29-73 单源模式、:76-118 多源模式),IDE 静态检查会按此提示用户。但实际实现是 def
assemble(*args, parallel: bool = False)(operation.py:121),运行时对参数数量、类型、两种模式的分派完全零校验。用户按 @overload 签名调用时,
任何偏差都触发 Python 内部的解包/迭代错误,错误信息不含函数名、签名提示或源代码位置。
Environment / 环境信息 (Mandatory / 必填)
服务器/NPU 型号: Ascend 910C
PyPTO 版本/Commit: 0.2.1
CANN 版本: 9.2.0(/home/operation/Ascend/ascend-toolkit)
Python 版本: 3.11.15
操作系统: Huawei Cloud EulerOS 2.0 (aarch64)
torch 版本: 2.7.1
torch_npu 版本: 2.7.1.post2
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
复现步骤 LSPs are disabled
Describe the expected behavior / 预期结果 (Mandatory / 必填)
@overload 仅为文档/静态类型检查,运行时无效果(operation.py:29-130) $0.00 spent
@overload LSP
def assemble(src: Tensor, offsets: List[Union[int, SymbolicScalar]], dst: Tensor, parallel: bool = False) -> None: LSPs are disabled
... # 仅类型提示
@overload
def assemble(srcs: Sequence[Tuple[Tensor, List[Union[int, SymbolicScalar]]]], dst: Tensor, parallel: bool = False) -> None:
... # 仅类型提示
def assemble(*args, parallel: bool = False) -> None:
# 运行时实现:无参数校验
if isinstance(args[0], Sequence):
srcs, dst = args # 解包失败 → 场景 A/C 的错误
else:
src, offsets, dst = args # 解包失败 → 场景 A/C 的错误
pypto_impl.Assemble(src.base(), to_syms(offsets), dst.base(), parallel)
# to_syms(0) → 'int' object is not iterable → 场景 B 的错误
行为隐晦
operation.py 中 assemble 模块函数无 @source_location 装饰器,即使错误被 C++ 层捕获,也无法附加用户源代码位置。
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
Special notes for this issue/备注 (Optional / 选填)