Module/Package-Class Unification
Is there a good reason why I can't do something like: import mypackage import mymodule x = mypackage(arg, kwarg) y = mymodule + 3 and other methods, etc. using the __special__ methods. Also, wouldn't it be cool if modules/packages could have metaclass- like handlers… I'm sure there's a good reason why this is just crazy talk implementation-wise, but I'd like to hear what it is. Python has merged types and classes, why not merging in packages and modules, too? -- Carl Johnson
Carl Johnson wrote:
Is there a good reason why I can't do something like:
import mypackage import mymodule
x = mypackage(arg, kwarg) y = mymodule + 3
and other methods, etc. using the __special__ methods.
Also, wouldn't it be cool if modules/packages could have metaclass-like handlers…
I'm sure there's a good reason why this is just crazy talk implementation-wise, but I'd like to hear what it is. Python has merged types and classes, why not merging in packages and modules, too?
Would these __special__ methods be seperate files like __init__.py is for packages? Ron
On Fri, Sep 19, 2008 at 10:14 AM, Ron Adam
Carl Johnson wrote:
Is there a good reason why I can't do something like:
import mypackage import mymodule
x = mypackage(arg, kwarg) y = mymodule + 3
and other methods, etc. using the __special__ methods.
Also, wouldn't it be cool if modules/packages could have metaclass-like handlers…
I'm sure there's a good reason why this is just crazy talk implementation-wise, but I'd like to hear what it is. Python has merged types and classes, why not merging in packages and modules, too?
Would these __special__ methods be seperate files like __init__.py is for packages?
I don't believe that was his intent. Generally though, this isn't difficult to do: override __import__. The ultimate question, however, is whether or not this improves code quality, readability, or maintainability. I don't believe it would, so aside from a "purist" approach to unifying, it fails in the face of practicality. - Josiah
participants (3)
-
Carl Johnson
-
Josiah Carlson
-
Ron Adam