diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-02-19 05:47:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-19 05:47:13 -0800 |
commit | 64ca72822338e0ba6e4f14d0a1cd3a9dcfa6c9ac (patch) | |
tree | 6686f10f39211d9fc639160aeedb690f472b3348 /Objects | |
parent | a8834905df853510f38d4e2d628bed8229fd7482 (diff) | |
download | cpython-git-64ca72822338e0ba6e4f14d0a1cd3a9dcfa6c9ac.tar.gz |
bpo-31506: Clarify error messages for object.__new__ and object.__init__ (GH-11641)
`object.__new__` and `object.__init__` do take one argument each,
they just don't take extra user supplied arguments.
Patch by Sanyam Khurana.
(cherry picked from commit 5105483acb3aca318304bed056dcfd7e188fe4b5)
Co-authored-by: Sanyam Khurana <8039608+CuriousLearner@users.noreply.github.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 4682105741..c578d6e935 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3654,11 +3654,13 @@ object_init(PyObject *self, PyObject *args, PyObject *kwds) PyTypeObject *type = Py_TYPE(self); if (excess_args(args, kwds)) { if (type->tp_init != object_init) { - PyErr_SetString(PyExc_TypeError, "object.__init__() takes no arguments"); + PyErr_SetString(PyExc_TypeError, + "object.__init__() takes exactly one argument (the instance to initialize)"); return -1; } if (type->tp_new == object_new) { - PyErr_Format(PyExc_TypeError, "%.200s().__init__() takes no arguments", + PyErr_Format(PyExc_TypeError, + "%.200s.__init__() takes exactly one argument (the instance to initialize)", type->tp_name); return -1; } @@ -3671,7 +3673,8 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { if (excess_args(args, kwds)) { if (type->tp_new != object_new) { - PyErr_SetString(PyExc_TypeError, "object.__new__() takes no arguments"); + PyErr_SetString(PyExc_TypeError, + "object.__new__() takes exactly one argument (the type to instantiate)"); return NULL; } if (type->tp_init == object_init) { |