Why does pickle reuse the existing Python class 'C' instead of reconstructing the class from the pickled bytes? Is there a way I can pickle and unpickle without side effects?
Here's my repl session:
In [1]: import pickle
In [2]: class C:
...: pass
...:
In [3]: hasattr(C, 'foo')
Out[3]: False
In [4]: pickled = pickle.dumps(C)
In [5]: C.foo = 'bar'
In [6]: hasattr(C, 'foo')
Out[6]: True
In [7]: C_without_foo = pickle.loads(pickled)
In [8]: hasattr(C_without_foo, 'foo')
Out[8]: True
In [9]: hasattr(C, 'foo')
Out[9]: True