Unifying modules and classes? (Re: [Python-Dev] a strange case) (original) (raw)

Greg Ewing greg@cosc.canterbury.ac.nz
Mon, 19 May 2003 14:05:16 +1200 (NZST)


Troy Melhase <troy@gci.net>:

Just last night, it occurred to me that modules could be made callable via subclassing. "Why in the world would you want callable modules you ask?"

This has given me a thought concerning the naming problem that arises when you have a module (e.g. socket) that exists mainly to hold a single class. What if there were some easy way to make the class and the module the same thing?

I'm thinking about having an alternative filename suffix, such as ".cls", whose contents is treated as though it were inside a class statement, and then the resulting class is put into sys.modules as though it were a module.

Not sure how you'd specify base classes -- maybe a special bases class attribute or something.

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 +--------------------------------------+