Skip to content

Instantly share code, notes, and snippets.

@bloodbare
Created January 25, 2018 00:06
Show Gist options
  • Save bloodbare/448fc5e594721b1d559182796d912665 to your computer and use it in GitHub Desktop.
Save bloodbare/448fc5e594721b1d559182796d912665 to your computer and use it in GitHub Desktop.
Guillotina Objects Slots
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