Open
multi_key_dict 对空 tuple/list key 组抛出 IndexError,缺少明确的参数校验 #2
super dog.Add on  May 25
super dog.
super dog.
May 25 Create

问题描述
multi_key_dict.__setitem__() 允许通过 tuple/list 一次写入多组 key,但当调用方传入空 tuple 或空 list 时,当前实现会直接执行 first_key = keys[0],最终抛出 IndexError: ... index out of range。这类异常既不直观,也无法向调用方说明真正的问题是“key 组不能为空”。

根因分析
__setitem__() 在识别到 keys 是 tuple/list 后,没有先校验长度是否为 0,就直接访问了第一个元素。

修复建议
在 keys 为 tuple/list 时先检查是否为空;若为空,应抛出语义更明确的异常(如 ValueError 或自定义消息的 KeyError),并补充最小回归验证覆盖空 tuple/list 两种输入。

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
May 25 Added label: sig/sig-python-modules
openeuler-ci-bot
openeuler-ci-botCollaborators
May 25 Comments:

Welcome To openEuler Community

Hey @papertager , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: sig-python-modules ,
and any of the maintainers: @shinwell_hu, @yangzhao_kl ,
and any of the committers: @gitee-cmd, @wk333 .

likedislike
super dog.super dog.
May 25 Associated pull request