1.1 --- a/lib/operator/core.py Tue Nov 29 17:25:54 2016 +0100
1.2 +++ b/lib/operator/core.py Tue Nov 29 17:27:31 2016 +0100
1.3 @@ -24,7 +24,7 @@
1.4
1.5 from native import _is as is_, _is_not as is_not
1.6
1.7 -def binary_op(a, b, left_accessor, right_accessor):
1.8 +def binary_op(a, b, left_accessor, right_accessor, default=None):
1.9
1.10 """
1.11 A single parameterised function providing the binary operator mechanism for
1.12 @@ -57,11 +57,14 @@
1.13 return result
1.14
1.15 # Where no methods were available, or if neither method could support the
1.16 - # operation, raise an exception.
1.17 + # operation, raise an exception or provide a default result.
1.18
1.19 - raise TypeError
1.20 + if default is None:
1.21 + raise TypeError
1.22 + else:
1.23 + return default
1.24
1.25 -def unary_op(a, accessor):
1.26 +def unary_op(a, accessor, default=None):
1.27
1.28 """
1.29 A single parameterised function providing the unary operator mechanism for
1.30 @@ -81,9 +84,12 @@
1.31 return result
1.32
1.33 # Where no method was available, or if the method could not support the
1.34 - # operation, raise an exception.
1.35 + # operation, raise an exception or provide a default result.
1.36
1.37 - raise TypeError
1.38 + if default is None:
1.39 + raise TypeError
1.40 + else:
1.41 + return default
1.42
1.43 def augassign(a, b, augmented_accessor, left_accessor, right_accessor):
1.44