You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I change a class variable defined in a module (in a file), I'm still getting the old value upon deserializing. This seems inconsistent when compared to dilling an interactively declared class, where the variable does indeed reflect the changed value.
Say we define a class in file A.py:
class A:
b = 1
In first Python shell I serialize the changed class:
>>> from A import A
>>> A.b
1
>>> A.b = 42
>>> A.b
42
>>> with open('A.pkl', 'w') as f: dill.dump(A, f)
...
In a second Python shell we deserialize, however the class variable retains the original value:
>>> with open('A.pkl', 'r') as f: A = dill.load(f)
...
>>> A.b
1
Interestingly enough, everything works as expected so long as I define my class interactively. For example, in first Python shell we can do:
>>> class A:
... b = 1
...
>>> A.b
1
>>> A.b = 42
>>> A.b
42
>>> with open('A.pkl', 'w') as f: dill.dump(A, f)
...
Then in second Python shell, the result is as expected:
>>> with open('A.pkl', 'r') as f: A = dill.load(f)
...
>>> A.b
42
The text was updated successfully, but these errors were encountered:
Yes, this is not a bug. I agree that it is a bit of an odd behavior -- and thus may be unexpected from a user perspective. @vmlaker: This is a totally valid issue… however I'm closing it as it is a duplicate of #42.
When I change a class variable defined in a module (in a file), I'm still getting the old value upon deserializing. This seems inconsistent when compared to dilling an interactively declared class, where the variable does indeed reflect the changed value.
Say we define a class in file
A.py
:In first Python shell I serialize the changed class:
In a second Python shell we deserialize, however the class variable retains the original value:
Interestingly enough, everything works as expected so long as I define my class interactively. For example, in first Python shell we can do:
Then in second Python shell, the result is as expected:
The text was updated successfully, but these errors were encountered: