1.1 --- a/lib/operator/comparison.py Fri Mar 24 19:07:01 2017 +0100
1.2 +++ b/lib/operator/comparison.py Fri Mar 24 22:08:50 2017 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Operator support.
1.6
1.7 -Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2010, 2013, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -20,6 +20,7 @@
1.13 """
1.14
1.15 from operator.core import binary_op
1.16 +from native import int_eq, int_ge, int_gt, int_le, int_lt, int_ne, is_int
1.17
1.18 # These functions defer method lookup by wrapping the attribute access in
1.19 # lambda functions. Thus, the appropriate methods are defined locally, but no
1.20 @@ -28,21 +29,33 @@
1.21 # Comparison functions.
1.22
1.23 def eq(a, b):
1.24 + if is_int(a) and is_int(b):
1.25 + return int_eq(a, b)
1.26 return binary_op(a, b, lambda a: a.__eq__, lambda b: b.__eq__, False)
1.27
1.28 def ge(a, b):
1.29 + if is_int(a) and is_int(b):
1.30 + return int_ge(a, b)
1.31 return binary_op(a, b, lambda a: a.__ge__, lambda b: b.__le__)
1.32
1.33 def gt(a, b):
1.34 + if is_int(a) and is_int(b):
1.35 + return int_gt(a, b)
1.36 return binary_op(a, b, lambda a: a.__gt__, lambda b: b.__lt__)
1.37
1.38 def le(a, b):
1.39 + if is_int(a) and is_int(b):
1.40 + return int_le(a, b)
1.41 return binary_op(a, b, lambda a: a.__le__, lambda b: b.__ge__)
1.42
1.43 def lt(a, b):
1.44 + if is_int(a) and is_int(b):
1.45 + return int_lt(a, b)
1.46 return binary_op(a, b, lambda a: a.__lt__, lambda b: b.__gt__)
1.47
1.48 def ne(a, b):
1.49 + if is_int(a) and is_int(b):
1.50 + return int_ne(a, b)
1.51 return binary_op(a, b, lambda a: a.__ne__, lambda b: b.__ne__, True)
1.52
1.53 # vim: tabstop=4 expandtab shiftwidth=4