New submission from jeffersonqin <1247006...@qq.com>:
For the following code piece:
```
import pickle
class Child:
def __init__(self, field):
self.field = field
class Parent:
child = Child(0.5)
if __name__ == '__main__':
i = input()
if i == 'd':
parent = Parent()
parent.child.field = 0.6
pickle.dump(parent, open('test.pkl', 'wb+'))
else:
parent = pickle.load(open('test.pkl', 'rb'))
print(parent.child.field)
```
After dumping, when we load the file throught `pickles.load`,
`parent.child.field` is 0.5, and is not 0.6, which we intend it to be.
However, after removing the line `child = Child(0.5)` and moving it to
`__init__(self)` of `Parent`, everything works fine.
I'm not sure whether this is indeed an issue. If not, sorry for take your time.
--
components: Library (Lib)
files: test.py
messages: 415341
nosy: jeffersonqin
priority: normal
severity: normal
status: open
title: pickle not working correctly when custom field is directly initialized
by constructors
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file50682/test.py
___
Python tracker
<https://bugs.python.org/issue47034>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com