mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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__ ........
This commit is contained in:
parent
499b2ee8a8
commit
a720559878
2 changed files with 16 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue