[New-bugs-announce] [issue35510] pickling derived dataclasses

Satrajit S Ghosh report at bugs.python.org
Sat Dec 15 22:22:21 EST 2018


New submission from Satrajit S Ghosh <satrajit.ghosh at gmail.com>:

I'm not sure if this is intended behavior or an error. I'm creating dataclasses dynamically and trying to pickle those classes or objects containing instances of those classes. This was resulting in an error, so I trimmed it down to this example.

```
import pickle as pk
import dataclasses as dc

@dc.dataclass
class A:
     pass
pk.dumps(A)  # --> this is fine

B = dc.make_dataclass('B', [], bases=(A,))
pk.dumps(B)  # --> results in an error

# PicklingError: Can't pickle <class 'types.B'>: attribute lookup B on types failed
```

is this expected behavior? and if so, is there a way to create a dynamic dataclass that pickles?

----------
components: Library (Lib)
messages: 331914
nosy: satra
priority: normal
severity: normal
status: open
title: pickling derived dataclasses
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35510>
_______________________________________


More information about the New-bugs-announce mailing list