diff options
author | Guido van Rossum <guido@python.org> | 2003-02-12 03:58:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-02-12 03:58:38 (GMT) |
commit | a89d10edc94b3c1c62a6920d4b6b8219675f36da (patch) | |
tree | 4b614ef1cd6bc73f36397b8e3320f0f70f412ee7 /Lib/test/test_descr.py | |
parent | e5b130bcdb491b7d4af7cd4c9cf82ebf6ba5fc63 (diff) | |
download | cpython-a89d10edc94b3c1c62a6920d4b6b8219675f36da.zip cpython-a89d10edc94b3c1c62a6920d4b6b8219675f36da.tar.gz cpython-a89d10edc94b3c1c62a6920d4b6b8219675f36da.tar.bz2 |
Implement another useful feature for proxies: in super(X, x), x may
now be a proxy for an X instance, as long as issubclass(x.__class__, X).
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r-- | Lib/test/test_descr.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 75ad135..77bf61a 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -3791,6 +3791,13 @@ def isinst_isclass(): pa = Proxy(a) verify(isinstance(a, C)) # Baseline verify(isinstance(pa, C)) # Test + # Test with a classic subclass + class D(C): + pass + a = D() + pa = Proxy(a) + verify(isinstance(a, C)) # Baseline + verify(isinstance(pa, C)) # Test # Test with a new-style class class C(object): pass @@ -3798,6 +3805,37 @@ def isinst_isclass(): pa = Proxy(a) verify(isinstance(a, C)) # Baseline verify(isinstance(pa, C)) # Test + # Test with a new-style subclass + class D(C): + pass + a = D() + pa = Proxy(a) + verify(isinstance(a, C)) # Baseline + verify(isinstance(pa, C)) # Test + +def proxysuper(): + if verbose: + print "Testing super() for a proxy object..." + 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) + + class B(object): + def f(self): + return "B.f" + + class C(B): + def f(self): + return super(C, self).f() + "->C.f" + + obj = C() + p = Proxy(obj) + vereq(C.__dict__["f"](p), "B.f->C.f") def test_main(): @@ -3887,6 +3925,7 @@ def test_main(): dict_type_with_metaclass() meth_class_get() isinst_isclass() + proxysuper() if verbose: print "All OK" |