Callable modules?

Jonathan Hogg jonathan at onegoodidea.com
Wed Jul 24 12:03:38 EDT 2002


On 24/7/2002 13:29, in article R4x%8.131291$vm5.4322201 at news2.tin.it, "Alex
Martelli" <aleax at aleax.it> wrote:

> It's because of a dislike of *language rules that don't carry their
> own weight* in general.  The more rules a language has, the more
> complicated it is.  Python is not complicated, but it could be
> even simpler if it were possible to remove all of the deadwood,
> and I include __call__ in that category.

I'm not sure I'm with you here. I find this aspect of Python to be quite
simple: everything is an object, and there is a mechanism supplied to
redefine each of the behaviours of an object through a special method.

To remove __call__ would invalidate that, such that there would be one
behaviour of an object that is suddenly reserved and not redefinable. This
would mean that implementing new callable types would only be possible
through the C interface. I think Python would lose tremendously by such a
move.

A bound method is just one kind of callable object, along with functions,
classes, metaclasses, classmethods and staticmethods. Without __call__ one
would need to bend one of these existing objects to create a callable
objects. But then you lose the ability to redefine other behaviours.

For example, there is no way of redefining the 'repr' of a function, or the
attribute interface. Without __call__ the closest I could come would be to
define a metaclass that creates class objects with a __new__ method
implementing the call interface - a truly monstrous idea.

Jonathan




More information about the Python-list mailing list