[New-bugs-announce] [issue25472] Typing: Specialized subclasses of generics cannot be unpickled

Matt Chaput report at bugs.python.org
Sat Oct 24 23:09:33 EDT 2015


New submission from Matt Chaput:

If I try to pickle and unpickle an object of a class that has specialized a generic superclass, when I try to unpickle I get this error:

TypeError: descriptor '__dict__' for 'A' objects doesn't apply to 'B' object

Test case:

from typing import Generic, TypeVar
import pickle

T = TypeVar("T")


class A(Generic[T]):
    def __init__(self, x: T):
        self.x = x


class B(A[str]):
    def __init__(self, x: str):
        self.x = x


b = B("hello")
z = pickle.dumps(b)
print(z)
_ = pickle.loads(z)

----------
messages: 253421
nosy: maatt
priority: normal
severity: normal
status: open
title: Typing: Specialized subclasses of generics cannot be unpickled
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25472>
_______________________________________


More information about the New-bugs-announce mailing list