Skip to content

Instantly share code, notes, and snippets.

@GrahamDumpleton
Created January 22, 2014 05:29
Show Gist options
  • Save GrahamDumpleton/8553894 to your computer and use it in GitHub Desktop.
Save GrahamDumpleton/8553894 to your computer and use it in GitHub Desktop.
The callable() function doesn't respect when __call__ is a descriptor.
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