Skip to content

gh-157747: Document that ** unpacking accepts any object with keys() - #162076

Open
themythofsisyphusjayant wants to merge 1 commit into
python:mainfrom
themythofsisyphusjayant:fix-gh-157747-dict-unpacking
Open

themythofsisyphusjayant wants to merge 1 commit into
python:mainfrom
themythofsisyphusjayant:fix-gh-157747-dict-unpacking

Conversation

@themythofsisyphusjayant

@themythofsisyphusjayant themythofsisyphusjayant commented Nov 16, 2026 •

Copy link
Copy Markdown

The Language Reference said ** unpacking, in both dictionary displays and calls, requires the expression to evaluate to a mapping — and the glossary defines a mapping as something implementing the full collections.abc.Mapping ABC. At runtime CPython only calls keys() and then __getitem__(), so objects like a pandas DataFrame work fine even though they are not mappings.

This rewords both places in Doc/reference/expressions.rst to match what the interpreter does, using the same wording as the dict constructor docs: the expression must evaluate to an object that defines a keys() method, with values obtained by calling __getitem__() with each returned key. A mapping satisfies this, but any object with those two methods does.

Checked by building the page with Sphinx (9.1.1, from Doc/requirements.txt): the page renders with the new wording at both spots. The only build warnings are pre-existing single-file-build artifacts, identical before and after the change.

Disclosure: I used an AI coding assistant to help prepare this change, and reviewed the diff myself before submitting.

@python-cla-bot

python-cla-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35915722 | 📁 Comparing 413d646 against main (7c59816)

  🔍 Preview build  

1 file changed
± reference/expressions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant