1.1 --- a/lib/__builtins__/str.py Tue Dec 13 17:58:26 2016 +0100
1.2 +++ b/lib/__builtins__/str.py Tue Dec 13 19:19:23 2016 +0100
1.3 @@ -74,12 +74,31 @@
1.4
1.5 def _binary_op(self, op, other):
1.6
1.7 - "Perform 'op' on this int and 'other' if appropriate."
1.8 + "Perform 'op' on this object and 'other' if appropriate."
1.9 +
1.10 + # Refuse to operate on specialisations of this class.
1.11 +
1.12 + if self.__class__ is not other.__class__:
1.13 + return NotImplemented
1.14 +
1.15 + # Otherwise, perform the operation on the operands' data.
1.16 +
1.17 + else:
1.18 + return op(self.__data__, other.__data__)
1.19
1.20 - if isinstance(other, basestring):
1.21 - return op(self.__data__, other.__data__)
1.22 + def _binary_op_rev(self, op, other):
1.23 +
1.24 + "Perform 'op' on 'other' and this object if appropriate."
1.25 +
1.26 + # Refuse to operate on specialisations of this class.
1.27 +
1.28 + if self.__class__ is not other.__class__:
1.29 + return NotImplemented
1.30 +
1.31 + # Otherwise, perform the operation on the operands' data.
1.32 +
1.33 else:
1.34 - return NotImplemented
1.35 + return op(other.__data__, self.__data__)
1.36
1.37 def __iadd__(self, other):
1.38
1.39 @@ -87,7 +106,13 @@
1.40
1.41 return self._binary_op(str_add, other)
1.42
1.43 - __add__ = __radd__ = __iadd__
1.44 + __add__ = __iadd__
1.45 +
1.46 + def __radd__(self, other):
1.47 +
1.48 + "Return a string combining this string with 'other'."
1.49 +
1.50 + return self._binary_op_rev(str_add, other)
1.51
1.52 def __mul__(self, other): pass
1.53 def __rmul__(self, other): pass