Last active
December 13, 2015 17:48
-
-
Save zeebo/4950798 to your computer and use it in GitHub Desktop.
A python object that always looks callable but actually isn't.
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
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