# HG changeset patch # User aurelien@trantor.local # Date 1266219639 -3600 # Mon Feb 15 08:40:39 2010 +0100 # Node ID 4318383b091a2847d49ba2d9f3511c4434c6f996 # Parent 74885982e3160261b2b214142029f86afb8ae30a [tests] diamond inheritance & next_method, ambiguous case diff --git a/dispatch.py b/dispatch.py --- a/dispatch.py +++ b/dispatch.py @@ -25,8 +25,8 @@ def __call__(self, *args): sig = signature(*args) self._pos = 0 - self._funcs = self.linearized_table(sig) if sig not in self._cache: + self._funcs = self.linearized_table(sig) func = self._funcs.pop() self._cache[sig] = func else: diff --git a/test/test_gf.py b/test/test_gf.py --- a/test/test_gf.py +++ b/test/test_gf.py @@ -75,6 +75,40 @@ self.assertTrue(beats(p, r)) self.assertFalse(beats(r, p)) + def test_deep_diamond(self): + class A(object): pass + class B(A): pass + class X(object): pass + class Y(X): pass + @method(A,X) + def foo(x,y): + return ('AX',) + @method(A,Y) + def foo(x,y): + return foo.next_method(x, y) + ('AY',) + @method(B,X) + def foo(x,y): + return foo.next_method(x, y) + ('BX',) + @method(B,Y) + def foo(x,y): + return foo.next_method(x, y) + ('BY',) + + b, y = B(), Y() + self.assertEquals(foo(b, y), ('AX', 'AY', 'BX', 'BY')) + + def test_ambiguity(self): + class A(object): pass + class B(A): pass + class X(object): pass + class Y(X): pass + @method(A,Y) + def foo(a,y): + return a,y + @method(B,X) + def foo(b,x): + return b,x + b, y = B(), Y() + print foo(b, y) if __name__ == '__main__': unittest.main()