gh-145876: preserve AttributeError in dict unpacking#145878
Conversation
Sorry, something went wrong.
|
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 |
Sorry, something went wrong.
There was a problem hiding this comment.
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_UPDATEto only convertAttributeErrorinto “not a mapping” whenupdate_otruly lacks akeysattribute; otherwise restore and propagate the original exception. - Regenerate the tier-1 interpreter cases to include the updated error-handling logic.
- Add doctest coverage ensuring
AttributeErrorfromkeys()/__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.
|
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. |
Sorry, something went wrong.
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
.keys()or.__getitem__()during{**mymapping}are incorrectly masked #145876