On Sat, Apr 18, 2015 at 2:23 PM, Steven D'Aprano <steve@pearwood.info> wrote:
Are you sure this doesn't already work? It works for me in Python 3.3:

It doesn't really work because of the incomplete checks done in `callable_builtin`. ​This is what I've tried:

>>> class DynamicCallable:
...     is_callable = True
...
...     def __init__(self, target):
...         self.target = target
...
...     @property
...     def __call__(self):
...         if self.is_callable:
...             return self.target
...         else:
...             raise AttributeError("Not really ...")
...
>>> dc = DynamicCallable(print)
>>> dc(1, 2, 3)
1 2 3
>>> callable(dc)
True
>>> dc.is_callable = False
>>> callable(dc)
True ###### This should be False :(

If the "bug" is fixed, then the last thing in the above example would return False.


Thanks,
-- Ionel
Cristian Mărieș, http://blog.ionelmc.ro