Skip to content

Instantly share code, notes, and snippets.

@zeebo
Last active December 13, 2015 17:48
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 zeebo/4950798 to your computer and use it in GitHub Desktop.
Save zeebo/4950798 to your computer and use it in GitHub Desktop.
A python object that always looks callable but actually isn't.
class HiddenImpl(object):
def __getattribute__(self, attr):
if attr == "__call__":
self.ref = Welp()
return self.ref
return object.__getattribute__(self, attr)
__getattr__ = __getattribute__
def __setattribute__(self, attr, value):
if attr not in ["__getattr__", "__getattribute__",
"__setattr__", "__setattribute__",
"__delattr__", "__delattribute__"]:
object.__setattr__(self, attr, value)
__setattr__ = __setattribute__
def __delattribute__(self, attr):
if attr not in ["__getattr__", "__getattribute__",
"__setattr__", "__setattribute__",
"__delattr__", "__delattribute__"]:
object.__delattr__(self, attr)
__delattr__ = __delattribute__
__call__ = None
class BaseHider(type):
__bases__ = (object, )
class Welp(HiddenImpl):
__metaclass__ = BaseHider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment