[issue31506] Improve the error message logic for object_new & object_init

Nick Coghlan report at bugs.python.org
Tue Feb 19 08:48:34 EST 2019


Nick Coghlan <ncoghlan at gmail.com> added the comment:

The revised behaviour now makes the error messages consistent with each other:

>>> class TooManyArgs():
...     def __new__(cls):
...         super().__new__(cls, 1)
... 
>>> TooManyArgs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __new__
TypeError: object.__new__() takes exactly one argument (the type to instantiate)
>>> class NotEnoughArgs():
...     def __new__(cls):
...         super().__new__()
... 
>>> NotEnoughArgs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __new__
TypeError: object.__new__(): not enough arguments
>>> class TooManyInitArgs():
...     def __init__(self):
...         super().__init__(1, 2, 3)
... 
>>> TooManyInitArgs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
>>> class NotEnoughInitArgs():
...     def __init__(self):
...         object.__init__()
... 
>>> NotEnoughInitArgs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
TypeError: descriptor '__init__' of 'object' object needs an argument

----------
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31506>
_______________________________________


More information about the Python-bugs-list mailing list