Skip to content

Instantly share code, notes, and snippets.

@miki725
Created March 12, 2018 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miki725/d8882343969bbcaf1251114a74559648 to your computer and use it in GitHub Desktop.
Save miki725/d8882343969bbcaf1251114a74559648 to your computer and use it in GitHub Desktop.
def SimpleProxy(subject):
def __getattribute__(self, item):
print(item)
if item == '__subject__':
return object.__getattribute__(self, item)
return getattr(self.__subject__, item)
attrs = {}
def make_getter(i):
def getter(self, *args, **kwargs):
print(i)
return getattr(self.__subject__, i)(*args, **kwargs)
return getter
for i in dir(subject):
if not (i.startswith('__') and i.endswith('__')) or i in ['__new__', '__init__']:
continue
attrs[i] = make_getter(i)
attrs.update({
'__subject__': subject,
'__getattribute__': __getattribute__,
})
return type(str('SimpleProxy'), (object,), attrs)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment