[Python-3000] callable()
Steven Bethard
steven.bethard at gmail.com
Thu Jul 27 20:27:12 CEST 2006
On 7/27/06, Guido van Rossum <guido at python.org> wrote:
> So how about we change callable() and add hashable(), iterable() and
> whatever else makes sense so that these all become like this:
>
> def callable(x):
> return getattr(x, "__call__", None) is not None
>
> This way classes can explicitly declare that they aren't callable,
> hashable, iterable etc. by setting the corresponding attribute to
> None.
FWLIW, I'm still about -0.5 on this. If you're defining a new class,
this gets you nothing as far as __iter__() and __call__() go -- just
don't define the method if you don't want it [1]. And how often do
you really want to define a subclass of an iterable or callable class
that is not iterable or callable? Maybe someone could post some
real-world use cases? I don't see what the added complexity is buying
us.
I also worry that it might set a bad precedent. Should we now also
add getitemable() and getattrable()? Maybe there's a good rule of
thumb for which *able() functions are needed, but I couldn't figure
one out.
STeVe
[1] It might get you something for __hash__() if object.__hash__() is
not removed, but that debate still seems to be in progress and I'm not
sure it's worth the added complexity to handle one special case.
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list