Skip to content

Commit 4c97097

Browse files
authored
Add a prim for 3-argument getattr (mypyc/mypyc#687)
1 parent 4182d11 commit 4c97097

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mypyc/lib-rt/CPy.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,17 @@ static PyObject *CPy_GetCoro(PyObject *obj)
972972
}
973973
}
974974

975+
static PyObject *CPyObject_GetAttr3(PyObject *v, PyObject *name, PyObject *defl)
976+
{
977+
PyObject *result = PyObject_GetAttr(v, name);
978+
if (!result && PyErr_ExceptionMatches(PyExc_AttributeError)) {
979+
PyErr_Clear();
980+
Py_INCREF(defl);
981+
result = defl;
982+
}
983+
return result;
984+
}
985+
975986
// mypy lets ints silently coerce to floats, so a mypyc runtime float
976987
// might be an int also
977988
static inline bool CPyFloat_Check(PyObject *o) {

mypyc/ops_misc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@
273273
emit=call_emit('PyObject_GetAttr')
274274
)
275275

276+
func_op(
277+
name='builtins.getattr',
278+
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive],
279+
result_type=object_rprimitive,
280+
error_kind=ERR_MAGIC,
281+
emit=call_emit('CPyObject_GetAttr3')
282+
)
283+
276284
py_setattr_op = func_op(
277285
name='builtins.setattr',
278286
arg_types=[object_rprimitive, object_rprimitive, object_rprimitive],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy