python / python/cpython

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

Open
#127,643 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Search CPython for the existing "object is not a mapping" error and trace the ** unpacking entry point; then add coverage for unpacking a list with ** and verify that the resulting TypeError identifies the operation and object type as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.