mirror of
https://github.com/python/cpython.git
synced 2025-09-02 23:18:25 +00:00
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.
This commit is contained in:
parent
60ceedbdd5
commit
16bf9bd157
3 changed files with 16 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue