mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Merged revisions 55545-55587 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55587 | guido.van.rossum | 2007-05-25 10:37:01 -0700 (Fri, 25 May 2007) | 2 lines Implement isinstance and issubclass overriding, a la PEP 3119. ........
This commit is contained in:
parent
573c08c1b7
commit
adee45ed2c
2 changed files with 113 additions and 2 deletions
|
@ -2130,7 +2130,25 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
|
|||
int
|
||||
PyObject_IsInstance(PyObject *inst, PyObject *cls)
|
||||
{
|
||||
return recursive_isinstance(inst, cls, Py_GetRecursionLimit());
|
||||
PyObject *t, *v, *tb;
|
||||
PyErr_Fetch(&t, &v, &tb);
|
||||
PyObject *checker = PyObject_GetAttrString(cls, "__instancecheck__");
|
||||
PyErr_Restore(t, v, tb);
|
||||
if (checker != NULL) {
|
||||
PyObject *res;
|
||||
int ok = -1;
|
||||
if (Py_EnterRecursiveCall(" in __instancecheck__"))
|
||||
return ok;
|
||||
res = PyObject_CallFunctionObjArgs(checker, inst, NULL);
|
||||
Py_LeaveRecursiveCall();
|
||||
Py_DECREF(checker);
|
||||
if (res != NULL) {
|
||||
ok = PyObject_IsTrue(res);
|
||||
Py_DECREF(res);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
return recursive_isinstance(inst, cls, Py_GetRecursionLimit());
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -2180,7 +2198,25 @@ recursive_issubclass(PyObject *derived, PyObject *cls, int recursion_depth)
|
|||
int
|
||||
PyObject_IsSubclass(PyObject *derived, PyObject *cls)
|
||||
{
|
||||
return recursive_issubclass(derived, cls, Py_GetRecursionLimit());
|
||||
PyObject *t, *v, *tb;
|
||||
PyErr_Fetch(&t, &v, &tb);
|
||||
PyObject *checker = PyObject_GetAttrString(cls, "__subclasscheck__");
|
||||
PyErr_Restore(t, v, tb);
|
||||
if (checker != NULL) {
|
||||
PyObject *res;
|
||||
int ok = -1;
|
||||
if (Py_EnterRecursiveCall(" in __subclasscheck__"))
|
||||
return ok;
|
||||
res = PyObject_CallFunctionObjArgs(checker, derived, NULL);
|
||||
Py_LeaveRecursiveCall();
|
||||
Py_DECREF(checker);
|
||||
if (res != NULL) {
|
||||
ok = PyObject_IsTrue(res);
|
||||
Py_DECREF(res);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
return recursive_issubclass(derived, cls, Py_GetRecursionLimit());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue