Issue 765228: Subclassing from Modules (original) (raw)
This issue has been migrated to GitHub: https://github.com/python/cpython/issues/38780
classification
Title: | Subclassing from Modules | ||
---|---|---|---|
Type: | Stage: | ||
Components: | Interpreter Core | Versions: | Python 2.4 |
process
Status: | closed | Resolution: | wont fix |
---|---|---|---|
Dependencies: | Superseder: | ||
Assigned To: | gvanrossum | Nosy List: | christian.heimes, georg.brandl, gvanrossum, lemburg |
Priority: | normal | Keywords: |
Created on 2003-07-03 10:32 by lemburg, last changed 2022-04-10 16:09 by admin. This issue is now closed.
Messages (4) | ||
---|---|---|
msg16833 - (view) | Author: Marc-Andre Lemburg (lemburg) * ![]() |
Date: 2003-07-03 10:32 |
In Python 2.2.3 there's a problem with accidental subclassing from a Python module, e.g. import MyStuff class A(MyStuff): pass this gives no error until you try to instantiate the class: o = A() TypeError: 'module' object is not callable In Python 2.3 the error is generated at module startup time: class A(MyStuff): pass TypeError: function takes at most 2 arguments (3 given) Since it is rather common that you create modules which have the same name as their most important class, I would find it more appropriate to raise a TypeError with a message "can't subclass a module instance" in both versions. | ||
msg55196 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2007-08-23 20:07 |
In 2.5, the message says "module.__init__() takes at most 2 arguments (3 given)", which is at least a bit more specific. You get similar errors when "deriving" from other arbitrary objects, so I don't know if a special case makes sense here. | ||
msg57776 - (view) | Author: Christian Heimes (christian.heimes) * ![]() |
Date: 2007-11-23 09:02 |
I agree. Python can't stop the developer from doing stupid things. We could remove Py_TPFLAGS_BASETYPE from the module type but that could cause incompatibilities with existing code. I'm assigning the bug to our beloved dictator to ask for his opinion. | ||
msg57837 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2007-11-26 04:16 |
I don't see an issue to be fixed here; adding special tests in order to provide more detailed error messages is rarely a good idea. Also, PEP 8 has said for years now that modules should *not* be named the same as classes. Yes, there are a few such modules in the standard library. They're historical mistakes that will be fixed in 3.0. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:09:40 | admin | set | github: 38780 |
2007-11-26 04:16:17 | gvanrossum | set | status: pending -> closedmessages: + |
2007-11-23 09:02:05 | christian.heimes | set | status: open -> pendingassignee: gvanrossumresolution: wont fixmessages: + nosy: + christian.heimes, gvanrossum |
2007-08-23 20:07:49 | georg.brandl | set | nosy: + georg.brandlmessages: + |
2003-07-03 10:32:45 | lemburg | create |