diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-07-30 22:45:19 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-07-30 22:45:19 (GMT) |
commit | 302b54acd91f999c039f9a3618f734dbdfb74467 (patch) | |
tree | 00b55c3c5beca1cd87dca09e9bcf4f952f32a4a8 /Python/bltinmodule.c | |
parent | c974bf4dc2031e8af5c64ac968a4a19054f5b097 (diff) | |
download | cpython-302b54acd91f999c039f9a3618f734dbdfb74467.zip cpython-302b54acd91f999c039f9a3618f734dbdfb74467.tar.gz cpython-302b54acd91f999c039f9a3618f734dbdfb74467.tar.bz2 |
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.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 571cfe2..ec55928 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(); |