diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-10-10 19:23:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-10 19:23:42 (GMT) |
commit | 98c4433a81a4cd88c7438adbee1f2aa486188ca3 (patch) | |
tree | 68dd030d113eb842692d4f50475992a110fb7154 /Objects | |
parent | 02a1603f918b9862e164e4fd050c505b16bc9f57 (diff) | |
download | cpython-98c4433a81a4cd88c7438adbee1f2aa486188ca3.zip cpython-98c4433a81a4cd88c7438adbee1f2aa486188ca3.tar.gz cpython-98c4433a81a4cd88c7438adbee1f2aa486188ca3.tar.bz2 |
bpo-41991: Remove _PyObject_HasAttrId (GH-22629)
It can silence arbitrary exceptions.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 11 | ||||
-rw-r--r-- | Objects/unionobject.c | 13 |
2 files changed, 7 insertions, 17 deletions
diff --git a/Objects/object.c b/Objects/object.c index 9889503..7bc3e48 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -855,17 +855,6 @@ _PyObject_GetAttrId(PyObject *v, _Py_Identifier *name) } int -_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name) -{ - int result; - PyObject *oname = _PyUnicode_FromId(name); /* borrowed */ - if (!oname) - return -1; - result = PyObject_HasAttr(v, oname); - return result; -} - -int _PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w) { int result; diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 8cfb2a6..89fdaf4 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -311,21 +311,22 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) _Py_IDENTIFIER(__args__); PyObject *qualname = NULL; PyObject *module = NULL; + PyObject *tmp; PyObject *r = NULL; int err; - int has_origin = _PyObject_HasAttrId(p, &PyId___origin__); - if (has_origin < 0) { + if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) { goto exit; } - if (has_origin) { - int has_args = _PyObject_HasAttrId(p, &PyId___args__); - if (has_args < 0) { + if (tmp) { + Py_DECREF(tmp); + if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) { goto exit; } - if (has_args) { + if (tmp) { // It looks like a GenericAlias + Py_DECREF(tmp); goto use_repr; } } |