[Python-ideas] TypeError: 'module' object is not callable

Chris Rebert pyideas at rebertia.com
Fri Feb 20 08:11:48 CET 2009

On Thu, Feb 19, 2009 at 9:52 PM, Ralf W. Grosse-Kunstleve
<rwgk at yahoo.com> wrote:
> I see there have been discussion about module __call__ about three years ago:
> http://mail.python.org/pipermail/python-list/2006-February/thread.html#366176
> Is there an existing pronouncement on this subject?
> __call__ would help avoiding strange things like from StringIO import StringIO
> or having to come up with silly names like run, driver, manager, etc.
> Ideally, __call__ could be either a function or class.
> I imagine, nothing special, except that a module object looks for __call__ instead
> of producing a type error.

IMHO, that seems like it would unreasonably blur the line between
whether a module is a class or an instance. If it has a __call__
definition in it, that would seem to imply that it is somehow a class.
But since you want to be able to call it on the module itself, that
seems to suggest that the module is an instance; but in that case,
lookup would start in the class 'module', not the module itself, and
thus fail. Seems your proposal would require modules to be some
strange hybrid and an exception to the normal Python rules. On this, I
defer to the Zen: " Special cases aren't special enough to break the

I don't find the StringIO case very odd, though I do think renaming
the module (and others in similar situations) to comply with PEP8
(i.e. "stringio" ) would help.


Follow the path of the Iguana...

More information about the Python-ideas mailing list