classification
Title: Misleading error message from object(arg)
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Alexander.Belopolsky, georg.brandl, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2010-02-18 23:14 by Alexander.Belopolsky, last changed 2013-02-19 03:12 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
issue7963.diff Alexander.Belopolsky, 2010-02-20 18:20 Patch against revision 78265 review
Messages (5)
msg99547 - (view) Author: Alexander Belopolsky (Alexander.Belopolsky) Date: 2010-02-18 23:14
>>> object(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object.__new__() takes no parameters


This is misleading because object.__new__() takes one parameter:

>>> object.__new__(object)
<object object at 0x100413980>


I suggest changing "object.__new__() takes no parameters" to "object() takes no parameters".

Some other inconsistencies that I noticed:

>>> tuple.__new__(tuple, 1, 2, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: tuple() takes at most 1 argument (3 given)

but

>>> list.__new__(list, 1, 2, 3)
[]
msg99568 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-02-19 10:28
The latter is no inconsistency; tuples are immutable, lists are not.  Therefore, for lists, __init__ is the initializer, not __new__.  In order not to duplicate argument checking, __new__ does nothing special with them.
msg182359 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-19 02:44
New changeset b5adf2a30b73 by R David Murray in branch '3.2':
#7963: fix error message when 'object' called with arguments.
http://hg.python.org/cpython/rev/b5adf2a30b73

New changeset 0e438442fddf by R David Murray in branch '3.3':
#7963: fix error message when 'object' called with arguments.
http://hg.python.org/cpython/rev/0e438442fddf

New changeset 1f3ce7ba410b by R David Murray in branch 'default':
Merge: #7963: fix error message when 'object' called with arguments.
http://hg.python.org/cpython/rev/1f3ce7ba410b
msg182360 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-19 03:05
New changeset 0082b7bf9501 by R David Murray in branch '2.7':
#7963: fix error message when 'object' called with arguments.
http://hg.python.org/cpython/rev/0082b7bf9501
msg182361 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-19 03:12
I've applied this.  Note that this makes the object.__new__ message consistent with, say, str.__new__.  That is, 'str.__new__(str, 2, 3)' results in the message "TypeError: str() argument 2 must be str, not int".  So the new object error message is consistent with that convention:  object.__new__(object, 1) now gives "TypeError: object() takes no parameters"
History
Date User Action Args
2013-02-19 03:12:18r.david.murraysetstatus: open -> closed

versions: + Python 3.2, Python 3.3, Python 3.4
nosy: + r.david.murray

messages: + msg182361
resolution: fixed
stage: resolved
2013-02-19 03:05:12python-devsetmessages: + msg182360
2013-02-19 02:44:38python-devsetnosy: + python-dev
messages: + msg182359
2010-02-20 18:21:00Alexander.Belopolskysetfiles: + issue7963.diff
keywords: + patch
2010-02-19 10:28:43georg.brandlsetnosy: + georg.brandl
messages: + msg99568
2010-02-18 23:14:23Alexander.Belopolskycreate