Created
January 25, 2018 00:06
-
-
Save bloodbare/448fc5e594721b1d559182796d912665 to your computer and use it in GitHub Desktop.
Guillotina Objects Slots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
class A(object): | |
__slots__ = ('__foo', '__bar') | |
@property | |
def _p_bar(self): | |
return object.__getattribute__(self, '_A__bar') | |
def __getstate__(self): | |
return self.__dict__ | |
class EE(A): | |
def __init__(self): | |
self.hola = 'hola' | |
# What is on the object | |
ee = EE() | |
ee._A__bar = 3 | |
assert '__bar' not in ee.__dict__ | |
assert ee._A__bar == 3 | |
try: | |
assert ee._A__car == 3 | |
raise Exception() | |
except AttributeError: | |
pass | |
assert ee._p_bar == 3 | |
ppp = pickle.dumps(ee) | |
eee = pickle.loads(ppp) | |
try: | |
assert eee._A__bar == 1 | |
raise Exception() | |
except AttributeError: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment