Created
January 22, 2014 05:29
-
-
Save GrahamDumpleton/8553894 to your computer and use it in GitHub Desktop.
The callable() function doesn't respect when __call__ is a descriptor.
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 Wrapper(object): | |
def __init__(self, wrapped): | |
self.__wrapped__ = wrapped | |
@property | |
def __call__(self): | |
return self.__wrapped__.__call__ | |
>>> wrapper = Wrapper(None) | |
>>> hasattr(wrapper, '__call__') | |
False | |
>>> getattr(wrapper, '__call__') | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "callable.py", line 8, in __call__ | |
return self.__wrapped__.__call__ | |
AttributeError: 'NoneType' object has no attribute '__call__' | |
>>> wrapper.__call__ | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "callable.py", line 8, in __call__ | |
return self.__wrapped__.__call__ | |
AttributeError: 'NoneType' object has no attribute '__call__' | |
>>> wrapper() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "callable.py", line 8, in __call__ | |
return self.__wrapped__.__call__ | |
AttributeError: 'NoneType' object has no attribute '__call__' | |
>>> callable(wrapper) | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment