1.1 --- a/lib/operator/core.py Sat Dec 10 00:56:32 2016 +0100
1.2 +++ b/lib/operator/core.py Sat Dec 10 14:02:44 2016 +0100
1.3 @@ -37,7 +37,7 @@
1.4
1.5 try:
1.6 fn = left_accessor(a)
1.7 - except AttributeError:
1.8 + except TypeError:
1.9 pass
1.10 else:
1.11 result = fn(b)
1.12 @@ -49,7 +49,7 @@
1.13
1.14 try:
1.15 fn = right_accessor(b)
1.16 - except AttributeError:
1.17 + except TypeError:
1.18 pass
1.19 else:
1.20 result = fn(a)
1.21 @@ -76,7 +76,7 @@
1.22
1.23 try:
1.24 fn = accessor(a)
1.25 - except AttributeError:
1.26 + except TypeError:
1.27 pass
1.28 else:
1.29 result = fn()
1.30 @@ -106,7 +106,7 @@
1.31
1.32 try:
1.33 fn = augmented_accessor(a)
1.34 - except AttributeError:
1.35 + except TypeError:
1.36 pass
1.37 else:
1.38 result = fn(b)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/operator_support.py Sat Dec 10 14:02:44 2016 +0100
2.3 @@ -0,0 +1,28 @@
2.4 +class A:
2.5 + def __init__(self, x):
2.6 + self.x = x
2.7 + def __sub__(self, other):
2.8 + return self.x - other.x
2.9 +
2.10 +class B:
2.11 + def __init__(self, x):
2.12 + self.x = x
2.13 + def __rsub__(self, other):
2.14 + return other.x - self.x
2.15 +
2.16 +class C:
2.17 + def __init__(self, x):
2.18 + self.x = x
2.19 +
2.20 +a = A(10)
2.21 +b = B(5)
2.22 +c = C(3)
2.23 +
2.24 +print a - b # 5
2.25 +print c - b # -2
2.26 +print a - c # 7
2.27 +
2.28 +try:
2.29 + print b - c # should raise an exception
2.30 +except TypeError:
2.31 + print "b - c: b and c do not respectively support the __sub__ and __rsub__ operations"