[Python-Dev] subclass a module?

Greg Ewing greg@cosc.canterbury.ac.nz
Tue, 04 Jun 2002 14:00:06 +1200 (NZST)

barry@zope.com (Barry A. Warsaw):

> Can I now subclass from modules?  And if so, what good does that do
> me?

This seems to be a side effect of two things:
(1) Python 2.2 will accept anything as a base class
whose type is callable with the appropriate arguments,
and (2) types.ModuleType doesn't seem to care what
arguments you give it:

Python 2.2 (#14, May 28 2002, 14:11:27) 
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> from types import ModuleType
>>> ModuleType()
<module '?' (built-in)>
>>> ModuleType(42)
<module '?' (built-in)>
>>> ModuleType("dead", "parrot")
<module '?' (built-in)>
>>> ModuleType("nobody", "expects", "the", "spanish", "base", "class")
<module '?' (built-in)>

So your class statement is simply creating an empty module.

An interesting feature of the new scheme is that the "class"
statement can be used to create things which don't even
remotely resemble classes. Brain-explosion for the masses!

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+