Issue563060
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2002-05-31 19:41 by nnorwitz, last changed 2022-04-10 16:05 by admin. This issue is now closed.
Messages (6) | |||
---|---|---|---|
msg10991 - (view) | Author: Neal Norwitz (nnorwitz) * | Date: 2002-05-31 19:41 | |
From python-dev: > But this is not what I would expect: > > >>> import string > >>> class newstr(string): pass > ... > # i would have expected this to raise a TypeError > >>> x = newstr() > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: 'module' object is not callable > > Perhaps this error should be handled when the class is constructed > rather than when instantiating an object? Guido says "the bug is that you can use any module as a base class" |
|||
msg10992 - (view) | Author: PJ Eby (pje) * | Date: 2002-05-31 20:27 | |
Logged In: YES user_id=56214 More specifically, ModuleType's constructor accepts and ignores a (name,bases,dict) call signature. Other objects will fail at class construction time like this: >>> class d({}): pass Traceback (most recent call last): File "<pyshell#1>", line 1, in ? class d({}): pass TypeError: dict() takes at most 1 argument (3 given) >>> class n(1): pass Traceback (most recent call last): File "<pyshell#3>", line 1, in ? class n(1): pass TypeError: int() takes at most 2 arguments (3 given) >>> class s("s"): pass Traceback (most recent call last): File "<pyshell#5>", line 1, in ? class s("s"): pass TypeError: str() takes at most 1 argument (3 given) >>> Since the module constructor doesn't actually need any arguments, it should complain the same way the above items do. Interestingly, while type(module) doesn't complain when called with excess arguments, the function 'new.module' does. Ironically, the docstring for new.module seems to imply it takes an argument. Perhaps new.module should simply refer to type(module), once the latter is fixed. Another, far more radical fix for this bug would be to change the constructor to accept the (name,bases,dict) signature, thus making it possible to subclass a module and have it work correctly, for some value of "correctly". :) |
|||
msg10993 - (view) | Author: Barry A. Warsaw (barry) * | Date: 2002-06-01 05:30 | |
Logged In: YES user_id=12800 Note that this bug exists in Python 2.2.1 also. |
|||
msg10994 - (view) | Author: Guido van Rossum (gvanrossum) * | Date: 2002-06-04 05:55 | |
Logged In: YES user_id=6380 Fixed. The module type's constructor now takes a name and an optional docstring argument (just like the C constructor PyModule_New()), and nothing else. Indeed, new.module can now be changed to point to the module type. |
|||
msg10995 - (view) | Author: Guido van Rossum (gvanrossum) * | Date: 2002-06-04 05:56 | |
Logged In: YES user_id=6380 This can't be fixed in 2.2.x without changing the module constructor signature, which I think is too much of an incompatibility to risk. (Hey, someone might even have a use fora module as a base class. :-) |
|||
msg10996 - (view) | Author: Just van Rossum (jvr) * | Date: 2002-11-29 20:22 | |
Logged In: YES user_id=92689 While I'm glad this is fixed, the error message for this fairly common newbie error is rather obscure: >>> import UserDict >>> class MyDict(UserDict): pass ... Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: function takes at most 2 arguments (3 given) >>> I have no idea if this is fixable at all. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:05:22 | admin | set | github: 36677 |
2002-05-31 19:41:34 | nnorwitz | create |