Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting changed value of class attribute in deserialized version #169

Closed
vmlaker opened this issue Jun 6, 2016 · 2 comments
Closed
Milestone

Comments

@vmlaker
Copy link

vmlaker commented Jun 6, 2016

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
@matsjoyce
Copy link
Contributor

This is (currently) expected behaviour. To support changing that, see #42.

@mmckerns
Copy link
Member

mmckerns commented Jun 9, 2016

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.

@mmckerns mmckerns closed this as completed Jun 9, 2016
@mmckerns mmckerns modified the milestone: dill-0.2.6 Feb 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants