1.1 --- a/inspector.py Thu Sep 22 22:08:37 2016 +0200
1.2 +++ b/inspector.py Thu Sep 22 22:15:50 2016 +0200
1.3 @@ -776,6 +776,11 @@
1.4 self.set_special(n.name, value)
1.5 return value
1.6
1.7 + # Test for self usage, which is only allowed in methods.
1.8 +
1.9 + if n.name == "self" and not (self.in_function and self.in_class):
1.10 + raise InspectError("Use of self is only allowed in methods.", path, n)
1.11 +
1.12 # Record usage of the name.
1.13
1.14 self.record_name(n.name)
2.1 --- a/lib/__builtins__/int.py Thu Sep 22 22:08:37 2016 +0200
2.2 +++ b/lib/__builtins__/int.py Thu Sep 22 22:15:50 2016 +0200
2.3 @@ -19,6 +19,7 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 +from __builtins__.operator import _binary_op, _negate
2.8 import native
2.9
2.10 class int(object):
2.11 @@ -135,24 +136,4 @@
2.12 "Return whether this int is non-zero."
2.13 return _negate(native._int_eq(self, 0))
2.14
2.15 -# Utility functions.
2.16 -
2.17 -def _binary_op(self, other, op):
2.18 -
2.19 - "Test the type of 'other' and perform 'op'."
2.20 -
2.21 - if self.__class__ is other.__class__:
2.22 - return op(self, other)
2.23 - else:
2.24 - return NotImplemented
2.25 -
2.26 -def _negate(result):
2.27 -
2.28 - "Negate any valid logical value."
2.29 -
2.30 - if result is NotImplemented:
2.31 - return result
2.32 - else:
2.33 - return not result
2.34 -
2.35 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/lib/__builtins__/operator.py Thu Sep 22 22:08:37 2016 +0200
3.2 +++ b/lib/__builtins__/operator.py Thu Sep 22 22:15:50 2016 +0200
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Operator-related functions.
3.6
3.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This program is free software; you can redistribute it and/or modify it under
3.11 the terms of the GNU General Public License as published by the Free Software
3.12 @@ -19,12 +19,12 @@
3.13 this program. If not, see <http://www.gnu.org/licenses/>.
3.14 """
3.15
3.16 -def _binary_op(self, other, op):
3.17 +def _binary_op(this, other, op):
3.18
3.19 - "Test the type of 'other' and perform 'op'."
3.20 + "Test the types of 'this' and 'other', performing 'op' if identical."
3.21
3.22 - if self.__class__ is other.__class__:
3.23 - return op(self, other)
3.24 + if this.__class__ is other.__class__:
3.25 + return op(this, other)
3.26 else:
3.27 return NotImplemented
3.28