Skip to content

Pickling deque subclasses ignores their __dict__. #4769

Description

@DimitrisJim

Caught after updating test_deque.py. In RustPython, pickling a deque subclass ignores its __dict__:

>>>>> import pickle
>>>>> from collections import deque
>>>>> class Deque(deque): pass
>>>>> d = Deque()
>>>>> d.x = "value"
>>>>> e = pickle.loads(pickle.dumps(pickle.HIGHEST_PROTOCOL))
>>>>> e.__dict__
{}

While in Python, __dict__ is correctly returned as {'x': 'value'}.

This doesn't appear to be the case with some other collections like list and dict so those could probably serve as an inspiration for what might be missing in deque.

For testing purposes, see test_copy_pickle in Lib/test/test_deque.py.

Activity

  1. added
    C-bugSomething isn't working
    C-compatA discrepancy between RustPython and CPython
    on Mar 25, 2023
  2. youknowone commented on Mar 25, 2023

    @youknowone
    Member

    Probably we are ignoring subclasses __dict__ for most of our __reduce__ implementations.

  3. DimitrisJim commented on Mar 25, 2023

    @DimitrisJim
    MemberAuthor

    Yeah, I'd bet collections should have most of them. Haven't checked the tests but if deque showed up now maybe similar ones will appear for the rest of the collections soon.

  4. youknowone commented on Oct 6, 2026

    @youknowone
    Member

    The originally reported problem no longer reproduces: pickling a deque subclass preserves instance __dict__ (test_copy_pickle passes). Closing per #8982.

    A leftover expectedFailure remains on test_pickle_recursive for DequeWithBadIter (pickle does not raise TypeError when __iter__ fails). That is a separate edge case from dropping subclass __dict__.

    — commented by Grok 4.6

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't workingC-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions