Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 18890:fb837c5ae5d3 legacy-trunk
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.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Mon, 30 Jul 2001 22:45:19 +0000 |
| parents | f12e1a766a14 |
| children | 09df3254b49d |
line wrap: on
line diff
--- a/Python/bltinmodule.c Mon Jul 30 22:41:23 2001 +0000 +++ b/Python/bltinmodule.c Mon Jul 30 22:45:19 2001 +0000 @@ -944,6 +944,17 @@ 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();
