GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-145876: preserve AttributeError in dict unpacking by zakiscoding · Pull Request #145878 · python/cpython

Conversation

@zakiscoding

@zakiscoding zakiscoding commented Mar 12, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Summary\n- preserve AttributeError raised from mapping methods during dict unpacking\n- keep TypeError for objects that are not mappings\n- add a regression test in test_unpack_ex\n\n## Testing\n- PCbuild\build.bat -p x64 -c Release\n- PCbuild\amd64\python.exe -m test -v test_unpack_ex\n\nCloses #145876

  • Issue: AttributeErrors raised in .keys() or .__getitem__() during {**mymapping}are incorrectly masked #145876

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zakiscoding
pythongh-145876: preserve AttributeError in dict unpacking
8a2bab8
@zakiscoding
zakiscoding requested a review from markshannon as a code owner March 12, 2026 20:10
Copilot AI review requested due to automatic review settings March 12, 2026 20:10
@python-cla-bot

python-cla-bot Bot commented Mar 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Mar 12, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Mar 12, 2026
AttributeErrors raised in .keys() or .__getitem__() during {**mymapping}are incorrectly masked #145876
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Mar 12, 2026
@picnixz picnixz closed this Mar 12, 2026
Copilot started reviewing on behalf of zakiscoding March 12, 2026 20:11
View session
Copilot AI reviewed Mar 12, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts dict-unpacking ({**obj} / DICT_UPDATE) error handling so that AttributeError raised from within a mapping’s keys() / __getitem__ is propagated, instead of being incorrectly rewritten as TypeError: '... object is not a mapping'.

Changes:

  • Update DICT_UPDATE to only convert AttributeError into “not a mapping” when update_o truly lacks a keys attribute; otherwise restore and propagate the original exception.
  • Regenerate the tier-1 interpreter cases to include the updated error-handling logic.
  • Add doctest coverage ensuring AttributeError from keys() / __getitem__ is preserved during dict unpacking.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Python/generated_cases.c.h Regenerated tier-1 interpreter DICT_UPDATE case to preserve AttributeError from mapping internals.
Python/bytecodes.c Updates the DICT_UPDATE bytecode definition’s error translation logic.
Lib/test/test_unpack_ex.py Adds doctests to ensure {**obj} propagates AttributeError raised by keys() / __getitem__.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/bytecodes.c
Comment on lines +2247 to +2251
PyObject *exc = PyErr_GetRaisedException();
PyObject *keys = NULL;
int has_keys = PyObject_GetOptionalAttr(update_o, &_Py_ID(keys), &keys);

if (has_keys < 0) {

Copilot AI Mar 12, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DICT_UPDATE now preserves the original AttributeError only when update_o has a keys attribute, but the tier-2 interpreter (Python/executor_cases.c.h) is generated from bytecodes.c and currently still contains the old unconditional conversion of AttributeError into TypeError. This will make behavior differ between tier-1 and tier-2 execution (and can break the new tests when tier-2 is enabled). Please regenerate/update the tier-2 cases so DICT_UPDATE matches this new logic everywhere.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
@picnixz

picnixz commented Mar 12, 2026

Copy link
Copy Markdown
Member

Note that LLM-generated PRs are not accepted unless acknlowedge and properly reviewed. Read https://devguide.python.org/getting-started/generative-ai/ before opening other PRs please.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@zakiscoding @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.