GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||
GeezerVison is showing github.com — gh-145876: preserve AttributeError in dict unpacking by zakiscoding · Pull Request #145878 · python/cpython Conversation
|
|
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 an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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:
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.AttributeError from keys() / __getitem__ is preserved during dict unpacking.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.
There was an error while loading. Please reload this page.
| PyObject *exc = PyErr_GetRaisedException(); | ||
| PyObject *keys = NULL; | ||
| int has_keys = PyObject_GetOptionalAttr(update_o, &_Py_ID(keys), &keys); | ||
|
|
||
| if (has_keys < 0) { |
There was a problem 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.
There was an error while loading. Please reload this page.
|
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.