Skip to content

Commit 9dc9fc3

Browse files
authored
[mypyc] Replace _CPyObject_HasAttr with PyObject_HasAttrWithError (#20535)
https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttrWithError
1 parent e4b04f8 commit 9dc9fc3

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

mypyc/lib-rt/dict_ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int CPyDict_Update(PyObject *dict, PyObject *stuff) {
159159
int CPyDict_UpdateFromAny(PyObject *dict, PyObject *stuff) {
160160
if (PyDict_CheckExact(dict)) {
161161
// Argh this sucks
162-
if (PyDict_Check(stuff) || _CPyObject_HasAttr(stuff, mypyc_interned_str.keys)) {
162+
if (PyDict_Check(stuff) || PyObject_HasAttrWithError(stuff, mypyc_interned_str.keys) > 0) {
163163
return PyDict_Update(dict, stuff);
164164
} else {
165165
return PyDict_MergeFromSeq2(dict, stuff, 1);
@@ -178,7 +178,7 @@ PyObject *CPyDict_FromAny(PyObject *obj) {
178178
if (!dict) {
179179
return NULL;
180180
}
181-
if (_CPyObject_HasAttr(obj, mypyc_interned_str.keys)) {
181+
if (PyObject_HasAttrWithError(obj, mypyc_interned_str.keys) > 0) {
182182
res = PyDict_Update(dict, obj);
183183
} else {
184184
res = PyDict_MergeFromSeq2(dict, obj, 1);

mypyc/lib-rt/pythonsupport.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,6 @@ _CPyDictView_New(PyObject *dict, PyTypeObject *type)
376376
}
377377
#endif
378378

379-
static int
380-
_CPyObject_HasAttr(PyObject *v, PyObject *name) {
381-
PyObject *tmp = NULL;
382-
int result = PyObject_GetOptionalAttr(v, name, &tmp);
383-
if (tmp) {
384-
Py_DECREF(tmp);
385-
}
386-
return result;
387-
}
388-
389379
#if CPY_3_12_FEATURES
390380

391381
// These are copied from genobject.c in Python 3.12

0 commit comments

Comments
 (0)