From: Jeremy Hylton Date: Mon, 30 Jul 2001 22:45:19 +0000 (+0000) Subject: Do for hasattr() what was done for getattr() X-Git-Tag: v2.2a3~918 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=302b54acd91f999c039f9a3618f734dbdfb74467;p=thirdparty%2FPython%2Fcpython.git Do for hasattr() what was done for getattr() Namely, an exception is raised if the second arg to hasattr() is not a string or Unicode. --- diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 571cfe2c8a10..ec55928cccc1 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -944,6 +944,17 @@ builtin_hasattr(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "OO:hasattr", &v, &name)) return NULL; + if (PyUnicode_Check(name)) { + name = _PyUnicode_AsDefaultEncodedString(name, NULL); + if (name == NULL) + return NULL; + } + + if (!PyString_Check(name)) { + PyErr_SetString(PyExc_TypeError, + "attribute name must be string"); + return NULL; + } v = PyObject_GetAttr(v, name); if (v == NULL) { PyErr_Clear();