◐ Shell
clean mode source ↗

gh-145876: preserve AttributeError in dict unpacking by zakiscoding · Pull Request #145878 · python/cpython

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__.