[issue47034] pickle not working correctly when custom field is directly initialized by constructors

2022-03-16 Thread Eric V. Smith
Eric V. Smith added the comment: You're probably doing something like: parent.i = 3 instead of: parent.child.field = 0.6 In the first one, you're setting an instance attribute on parent, on the second, you're modifying an attribute of the class attribute. In any event, there's no bug

[issue47034] pickle not working correctly when custom field is directly initialized by constructors

2022-03-16 Thread jeffersonqin
jeffersonqin <1247006...@qq.com> added the comment: Thanks! This fully answers my question. Sorry, but I've got another question regards to your answer. It is that when I deal with other fields in class Parent similar to child, with the only difference is that their types are builtin types

[issue47034] pickle not working correctly when custom field is directly initialized by constructors

2022-03-16 Thread Eric V. Smith
Eric V. Smith added the comment: child is not an attribute of a Parent instance, but rather of the Parent class. So it's not going to be saved when you dump "parent", which is an instance of Parent. I'm not sure what you're doing when you create a Parent.__init__ method, but presumably

[issue47034] pickle not working correctly when custom field is directly initialized by constructors

2022-03-16 Thread jeffersonqin
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 ==