[Python-bugs-list] [ python-Bugs-638610 ] Instantiation init-less class with param
SourceForge.net
noreply@sourceforge.net
Wed, 12 Feb 2003 21:28:05 -0800
Bugs item #638610, was opened at 2002-11-14 19:53
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=638610&group_id=5470
Category: Type/class unification
Group: Python 2.3
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Shalabh Chaturvedi (shalabh)
Assigned to: Nobody/Anonymous (nobody)
Summary: Instantiation init-less class with param
Initial Comment:
Instantiation new style __init__-less class with
parameters does not raise exception. Old style classes
raise TypeError: this constructor takes no arguments.
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit
(Intel)] on win32
>>> class C:
... pass
...
>>> c = C('extra', 'params')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: this constructor takes no arguments
>>>
>>> class C(object):
... pass
...
>>> c = C('whos','eating','my', 'params')
>>> c
<__main__.C object at 0x007A49B8>
>>>
Who?
----------------------------------------------------------------------
Comment By: Michael Stone (mbrierst)
Date: 2003-02-13 05:28
Message:
Logged In: YES
user_id=670441
I agree that having separate __new__ and __init__ objects is a feature, but this can be preserved while also throwing an exception in the example given. When no __new__ OR __init__ has overriden the base object's new and init, arguments passed to them will be silently ignored. It seems preferable in that case to throw a type exception. If either one has been overridden, it will determine the class signature and throw an exception when appropriate.
I submitted a patch to implement this as #685738.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-12 22:36
Message:
Logged In: YES
user_id=6380
This is a feature. You inherit both a __new__ and a __init__
from object that ignore their arguments; this is so that you
can write a class that defines one but not the other, and
its signature then forces the class's signature.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-20 18:29
Message:
Logged In: YES
user_id=33168
Changed to 2.3 and bumped priority in the hopes that this
can/will be fixed for 2.3.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-11-15 10:14
Message:
Logged In: YES
user_id=6656
This is known behaviour (at least, I knew about it <wink>).
This is why:
>>> object(1,2,3)
<object object at 0x818dfb8>
I seem to recall discussion that this had to be left alone
in 2.2.X but should be fixed in 2.3...
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-14 23:26
Message:
Logged In: YES
user_id=33168
Confirmed the behaviour in 2.2.2 and 2.3.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=638610&group_id=5470