Callable modules?
Martin v. Loewis
martin at v.loewis.de
Tue Jul 23 03:07:01 EDT 2002
Paul Rubin <phr-n2002b at NOSPAMnightsong.com> writes:
> > considering the backwards incompatibility, it makes no sense to add a
> > __call__ right now.
>
> What incompatibility? Do you think people are out there writing
> modules with __call__ functions, and then depending on raising an
> exception when they call the module directly?
There is no incompatibility. Having or not having an __call__ method
(i.e. a tp_call slot) is a property of the type, not a property of the
instance. Each module is an instance of the module type, so you need
to look at the module type - and it turns out it simply doesn't have
an __call__ method.
Now, if you could create modules of different types, they might have
__call__ methods. There just isn't any syntax to create modules of
different types. Asking for __call__ on modules is like asking for
__call__ on, say, numbers:
def call(self, *args):pass
1.__call__ = call
1("Hello, World")
Regards,
Martin
More information about the Python-list
mailing list