[Python-ideas] Fix that broken callable builtin
Chris Angelico
rosuav at gmail.com
Sat Apr 18 14:25:19 CEST 2015
On Sat, Apr 18, 2015 at 9:41 PM, Ionel Cristian Mărieș
<contact at ionelmc.ro> wrote:
>>>> 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 ...")
Before charging ahead and making the callable() function check for
this, is it actually a supported concept? Is it intentional that
property-getter functions can raise AttributeError to signal that the
attribute does not (currently) exist? Because if that's a hack, then
there's no reason to support it, and callable() is absolutely correct
to say "there is a __call__ attribute on the class, ergo it's
callable".
ChrisA
More information about the Python-ideas
mailing list