summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-27 03:08:59 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-27 03:08:59 (GMT)
commita720559878f25f3f8ed46a81260844231bfc9d4b (patch)
tree57b4275ac5e113bbbd889c9521d9e6b2aad3a007
parent499b2ee8a8c2a498cb068f09f6be1bfb6da85225 (diff)
downloadcpython-a720559878f25f3f8ed46a81260844231bfc9d4b.zip
cpython-a720559878f25f3f8ed46a81260844231bfc9d4b.tar.gz
cpython-a720559878f25f3f8ed46a81260844231bfc9d4b.tar.bz2
Merged revisions 72957 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72957 | benjamin.peterson | 2009-05-26 21:43:46 -0500 (Tue, 26 May 2009) | 1 line correctly handle descrs with __missing__ ........
-rw-r--r--Lib/test/test_descr.py11
-rw-r--r--Objects/dictobject.c11
2 files changed, 16 insertions, 6 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index adcb55f..5c50571 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1562,6 +1562,13 @@ order (MRO) for bases """
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
@@ -1573,6 +1580,8 @@ order (MRO) for bases """
{"__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
@@ -1588,7 +1597,7 @@ order (MRO) for bases """
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
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index b39c614..97fa60b 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1128,13 +1128,14 @@ dict_subscript(PyDictObject *mp, register PyObject *key)
/* 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;