summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-12 03:32:58 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-12 03:32:58 (GMT)
commit03bc7d3c4d22146b2e28c39e6c2e239137318f0a (patch)
tree3a926bb496d70ae4bd0445b5db5889b226ceaad7 /Lib/test
parent73019a6321ba3718e31c110c290b94949be1b70f (diff)
downloadcpython-03bc7d3c4d22146b2e28c39e6c2e239137318f0a.zip
cpython-03bc7d3c4d22146b2e28c39e6c2e239137318f0a.tar.gz
cpython-03bc7d3c4d22146b2e28c39e6c2e239137318f0a.tar.bz2
SF #532767: isinstance(x, X) should work when x is a proxy for an X
instance, as long as x.__class__ is X or a subclass thereof. Did a little cleanup of PyObject_IsInstance() too.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_descr.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index f481205..75ad135 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3735,7 +3735,8 @@ def dict_type_with_metaclass():
def meth_class_get():
# Full coverage of descrobject.c::classmethod_get()
- if verbose: print "Testing __get__ method of METH_CLASS C methods..."
+ if verbose:
+ print "Testing __get__ method of METH_CLASS C methods..."
# Baseline
arg = [1, 2, 3]
res = {1: None, 2: None, 3: None}
@@ -3772,6 +3773,32 @@ def meth_class_get():
else:
raise TestFailed, "shouldn't have allowed descr.__get__(None, int)"
+def isinst_isclass():
+ if verbose:
+ print "Testing proxy isinstance() and isclass()..."
+ class Proxy(object):
+ def __init__(self, obj):
+ self.__obj = obj
+ def __getattribute__(self, name):
+ if name.startswith("_Proxy__"):
+ return object.__getattribute__(self, name)
+ else:
+ return getattr(self.__obj, name)
+ # Test with a classic class
+ class C:
+ pass
+ a = C()
+ pa = Proxy(a)
+ verify(isinstance(a, C)) # Baseline
+ verify(isinstance(pa, C)) # Test
+ # Test with a new-style class
+ class C(object):
+ pass
+ a = C()
+ pa = Proxy(a)
+ verify(isinstance(a, C)) # Baseline
+ verify(isinstance(pa, C)) # Test
+
def test_main():
do_this_first()
@@ -3859,6 +3886,7 @@ def test_main():
subclass_right_op()
dict_type_with_metaclass()
meth_class_get()
+ isinst_isclass()
if verbose: print "All OK"