python / python/cpython

Clarify error message when unpacking objects with `*` and `**`

未关闭
#127,643 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

When attempting to unpack a list (or any other non-mapping) as a mapping, one gets this error message:

builtins.TypeError: 'list' object is not a mapping

It's confusing, especially since sometimes the unpacking is done on a long multi-line statement, and it's not clear that the unpacking is the source of the error.

I suggest modifying to:

builtins.TypeError: Can't unpack 'list' object using ** because it's not a mapping

I'll be happy to submit a pull request if you agree with this change.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定文件或测试。搜索 CPython 中现有的 "object is not a mapping" 错误,并跟踪 ** 解包入口点;然后为使用 ** 解包列表添加覆盖,并验证生成的 TypeError 按要求标识操作和对象类型。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
compilers
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。