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.

Title: Confusing error message when initialising type inheriting object.__init__
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Gerrit.Holl, iritkatriel, r.david.murray
Priority: normal Keywords:

Created on 2014-06-11 22:06 by Gerrit.Holl, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg220313 - (view) Author: Gerrit Holl (Gerrit.Holl) * Date: 2014-06-11 22:06
When I initialise a class that doesn't define its own __init__, but I still pass arguments, the error message is confusing:

>>> class A: pass
>>> A(42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object() takes no parameters

Although it is correct that object() takes no parameters, it would be more correct to state that A() does not take any parameters.
msg220319 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-11 22:46
See issue 7963 for a clue to why you get this message.  That is, it is object.__new__ that is getting called, not object.__init__, and __new__ methods result in different error messages than __init__ methods.  I don't know if there is a practical way to make it better.  For example you also have this:

>>> a = A('abc', 'xyz')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: decoding str is not supported
>>> a = A('abc', 2, 3, 54)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: str() takes at most 3 arguments (4 given)
msg386495 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-04 21:50
Looks like this was fixed under issue31506.

In any case it works for me now: 

>>> A(42)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: A() takes no arguments
Date User Action Args
2022-04-11 14:58:04adminsetgithub: 65927
2021-04-16 19:04:07iritkatrielsetstatus: pending -> closed
stage: resolved
2021-02-04 21:50:40iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg386495

resolution: fixed
2014-06-11 22:46:21r.david.murraysetnosy: + r.david.murray
messages: + msg220319
2014-06-11 22:06:57Gerrit.Hollcreate