[Python-ideas] Fix that broken callable builtin
Ionel Cristian Mărieș
contact at ionelmc.ro
Sat Apr 18 13:41:29 CEST 2015
On Sat, Apr 18, 2015 at 2:23 PM, Steven D'Aprano <steve at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150418/f49ddc92/attachment.html>
More information about the Python-ideas
mailing list