[Python-bugs-list] [ python-Bugs-563060 ] Module can be used as a base class
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 31 May 2002 13:27:29 -0700
Bugs item #563060, was opened at 2002-05-31 19:41
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=563060&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Neal Norwitz (nnorwitz)
Assigned to: Nobody/Anonymous (nobody)
Summary: Module can be used as a base class
Initial Comment:
>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"
----------------------------------------------------------------------
Comment By: Phillip J. Eby (pje)
Date: 2002-05-31 20:27
Message:
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". :)
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=563060&group_id=5470