1.1 --- a/lib/operator/unary.py Fri Mar 24 19:07:01 2017 +0100
1.2 +++ b/lib/operator/unary.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 unary_op
1.16 +from native.int import int_neg, int_not, 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 @@ -31,12 +32,18 @@
1.21 return unary_op(a, lambda a: a.__invert__)
1.22
1.23 def neg(a):
1.24 + if is_int(a):
1.25 + return int_neg(a)
1.26 return unary_op(a, lambda a: a.__neg__)
1.27
1.28 def not_(a):
1.29 + if is_int(a):
1.30 + return int_not(a)
1.31 return not a
1.32
1.33 def pos(a):
1.34 + if is_int(a):
1.35 + return a
1.36 return unary_op(a, lambda a: a.__pos__)
1.37
1.38 # vim: tabstop=4 expandtab shiftwidth=4