[Python-ideas] Fix that broken callable builtin

Ionel Cristian Mărieș contact at ionelmc.ro
Sat Apr 18 18:33:55 CEST 2015


On Sat, Apr 18, 2015 at 3:25 PM, Chris Angelico <rosuav at gmail.com> wrote:

> 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".
>

​It's hard to say what's intended or not. At best is speculation, as
python-the-language does not have a specification. What we have now is made
up from many contributions from many people.

What we should talk about is "do we want to have this intent or not". Now
that's a worthwhile discussion​, that can avoid speculation and
subjectivity about what's in the docs, what's a hack in contrast to what is
in the docs, what's and if there's prior use. You can't talk about how tall
your house is going to be until you know what you build it on - is it sand
or is it rock?

>From my perspective consistency is very important, and it's lacking here
w.r.t. how `callable` behaves versus `hasattr` or the call operator. The
`iter` builtin already handles `__iter__` differently compared to how
`callable` handles `__call__` so there, what do we do with that then? Do we
make `iter` raise AttributeError or TypeError (as it's now)? I strongly
believe fixing `callable` is the shortest way to achieve some consistency
here.



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/d805f256/attachment.html>


More information about the Python-ideas mailing list