return isinstance(int, obj)
def do_issubclass(obj):
return issubclass(int, obj)
+ def do_dict_missing(checker):
+ class DictSub(checker.__class__, dict):
+ pass
+ self.assertEqual(DictSub()["hi"], 4)
+ def some_number(self_, key):
+ self.assertEqual(key, "hi")
+ return 4
# It would be nice to have every special method tested here, but I'm
# only listing the ones I can remember outside of typeobject.c, since it
{"__iter__" : iden, "__next__" : stop}),
("__sizeof__", sys.getsizeof, zero, set(), {}),
("__instancecheck__", do_isinstance, return_true, set(), {}),
+ ("__missing__", do_dict_missing, some_number,
+ set(("__class__",)), {}),
("__subclasscheck__", do_issubclass, return_true,
set(("__bases__",)), {}),
# These two fail because the compiler generates LOAD_ATTR to look
def __getattribute__(self, attr, test=self):
if attr not in ok:
test.fail("__getattribute__ called with {0}".format(attr))
- return object.__getattribute__(attr)
+ return object.__getattribute__(self, attr)
class SpecialDescr(object):
def __init__(self, impl):
self.impl = impl
/* Look up __missing__ method if we're a subclass. */
PyObject *missing;
static PyObject *missing_str = NULL;
- if (missing_str == NULL)
- missing_str =
- PyUnicode_InternFromString("__missing__");
- missing = _PyType_Lookup(Py_TYPE(mp), missing_str);
+ missing = _PyObject_LookupSpecial((PyObject *)mp,
+ "__missing__",
+ &missing_str);
if (missing != NULL)
return PyObject_CallFunctionObjArgs(missing,
- (PyObject *)mp, key, NULL);
+ key, NULL);
+ else if (PyErr_Occurred())
+ return NULL;
}
set_key_error(key);
return NULL;