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

Nick Coghlan report at bugs.python.org
Mon Sep 24 08:06:19 EDT 2018


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

We added the method names to help provide a nudge that the issue is likely to be a missing method implementation in the subclassing case, so I'd like to keep them if we can find a way to make the messages accurate again.

What if we updated the offending format strings in typeobject.c to state the exact nature of the expected argument that is missing?

    PyErr_SetString(PyExc_TypeError, "object.__init__() takes exactly one argument (the instance to initialize)");

    PyErr_Format(PyExc_TypeError, "%.200s.__init__() takes exactly one argument (the instance to initialize)", type->tp_name);

    PyErr_SetString(PyExc_TypeError, "object.__new__() takes exactly one argument (the type to instantiate)")

----------

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


More information about the Python-bugs-list mailing list