[issue35510] pickling derived dataclasses

2018-12-16 Thread Satrajit S Ghosh


Satrajit S Ghosh  added the comment:

Thank you.

--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35510] pickling derived dataclasses

2018-12-16 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Dataclasses are pickled by name, as well as other classes. Pickling classes 
which can not be accessed by name is not supported.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35510] pickling derived dataclasses

2018-12-16 Thread Satrajit S Ghosh


Satrajit S Ghosh  added the comment:

thank you + serhiy.storchaka

while that works in an interactive namespace, it fails in the following 
setting, which is closer to my dynamic use case.

```
class A:
def __init__(self, fields=None):
self.B = dc.make_dataclass('B', fields or [])
self.B.__module__ = __name__
# ...
self.C = self.B()
```

now pickling A() fails.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35510] pickling derived dataclasses

2018-12-15 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

You need to set the __module__ attribute.

B.__module__ = __name__

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35510] pickling derived dataclasses

2018-12-15 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35510] pickling derived dataclasses

2018-12-15 Thread Satrajit S Ghosh


New submission from Satrajit S Ghosh :

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 : 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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com