Skip to content

gh-158126: Avoid creating AttributeError for optional Pickler attribute lookups - #158148

Open
lazerg wants to merge 1 commit into
python:mainfrom
lazerg:fix-issue-158126
Open

lazerg wants to merge 1 commit into
python:mainfrom
lazerg:fix-issue-158126

Conversation

@lazerg

@lazerg lazerg commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Since Pickler got its own tp_getattro for persistent_id, PyObject_GetOptionalAttr() no longer takes its fast path for it, so every dump() builds and clears an AttributeError when it looks up reducer_override, and __init__() does the same for dispatch_table. When the type still uses Pickler_getattr, this now calls _PyObject_GenericGetAttrWithDict() with suppress=1 directly. Pickler_getattr only special-cases persistent_id, so the result is the same. Subclasses that override __getattr__ or __getattribute__ keep the old path.

Fixes #158126

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pickle.dumps() creates and discards an AttributeError on every call since 3.13.1

1 participant