TypeError: 'module' object is not callable

I see there have been discussion about module __call__ about three years ago: http://mail.python.org/pipermail/python-list/2006-February/thread.html#36617... 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.

On Thu, Feb 19, 2009 at 9:52 PM, Ralf W. Grosse-Kunstleve <rwgk@yahoo.com> wrote:
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 rules." 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. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com

Oh, we could easily add a __call__ to the module type that looks for a __call__ function. I just don't think it's a good idea. On Fri, Feb 20, 2009 at 9:35 AM, Christian Heimes <lists@cheimes.de> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

On Thu, Feb 19, 2009 at 9:52 PM, Ralf W. Grosse-Kunstleve <rwgk@yahoo.com> wrote:
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 rules." 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. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com

Oh, we could easily add a __call__ to the module type that looks for a __call__ function. I just don't think it's a good idea. On Fri, Feb 20, 2009 at 9:35 AM, Christian Heimes <lists@cheimes.de> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (5)
-
Chris Rebert
-
Christian Heimes
-
Guido van Rossum
-
Ralf W. Grosse-Kunstleve
-
Steven D'Aprano