From 16bf9bd157c7bf5f9c60414fa8e0fe5047c55a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Ogam?= Date: Tue, 18 Jan 2022 21:46:26 +0100 Subject: bpo-44024: Improve the TypeError message in getattr and hasattr (GH-25863) Use common error message for non-string attribute name in the builtin functions getattr and hasattr. The special check no longer needed since Python 3.0. --- Python/bltinmodule.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 6763f99697..ef1b2bb9cf 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1091,11 +1091,6 @@ builtin_getattr(PyObject *self, PyObject *const *args, Py_ssize_t nargs) v = args[0]; name = args[1]; - if (!PyUnicode_Check(name)) { - PyErr_SetString(PyExc_TypeError, - "getattr(): attribute name must be string"); - return NULL; - } if (nargs > 2) { if (_PyObject_LookupAttr(v, name, &result) == 0) { PyObject *dflt = args[2]; @@ -1156,11 +1151,6 @@ builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name) { PyObject *v; - if (!PyUnicode_Check(name)) { - PyErr_SetString(PyExc_TypeError, - "hasattr(): attribute name must be string"); - return NULL; - } if (_PyObject_LookupAttr(obj, name, &v) < 0) { return NULL; } -- cgit v1.2.1