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 — Support pickling of super object · Issue #125767 · python/cpython

Support pickling of super object #125767

New issue
Copy link
New issue
Copy link
Closed
Closed
Support pickling of super object#125767
Copy link
Assignees
serhiy-storchaka
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Oct 21, 2024
Issue body actions

Feature or enhancement

As was noted in #125714 (comment), the super object is not pickleable. For example:

import pickle
class X: pass
s = super(X, X())
pickle.dumps(s)

Produces a traceback:

Traceback (most recent call last):
  File "<python-input-0>", line 4, in <module>
    pickle.dumps(s)
    ~~~~~~~~~~~~^^^
_pickle.PicklingError: first argument to __newobj__() must be <class 'super'>, not <class '__main__.X'>
when serializing super object

This is because the special methods like __reduce_ex__() are looked up in an instance and translated to a lookup in the underlying object.

>>> super(X, X()).__reduce_ex__(5)
(<function __newobj__ at 0x7fd9e8a0ad50>, (<class '__main__.X'>,), None, None, None)

This cannot be solved by implementing the __reduce_ex__() method in the super class, because the current behavior is expected when super() is used in the __reduce_ex__() implementation of some subclass. The super class likely should be registered in the global dispatch table.

There may be similar issue with shallow and deep copying.

Linked PRs

  • gh-125767: Fix pickling and copying of super objects #125781
Reacted by blhsing and Vaibhav Tiwari

Activity

  1. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Oct 21, 2024
  2. serhiy-storchaka
    added this to Pickle and copy issues 🥒on Oct 21, 2024
  3. serhiy-storchaka
    self-assigned this
    on Oct 21, 2024
  4. serhiy-storchaka
    added 3 commits that reference this issue on Oct 21, 2024

    pythongh-125767: Fix pickling and copying

    ae557da

    pythongh-125767: Fix pickling and copying of super objects

    56b7e25

    gh-125767: Fix pickling and copying of super objects (GH-125781)

    5ca4e34
  5. serhiy-storchaka
    closed this as completedon Oct 21, 2024
  6. github-project-automation
    moved this to Done in Pickle and copy issues 🥒on Oct 21, 2024
  7. ebonnal
    added a commit that references this issue on Jan 12, 2025

    pythongh-125767: Fix pickling and copying of super objects (pythonGH-…

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

Metadata

Metadata

Assignees

  • @serhiy-storchaka
    serhiy-storchaka

Labels

type-featureA feature request or enhancementA feature request or enhancement

Projects

  • Pickle and copy issues 🥒
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402520 — 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.