diff -r dfe7d9fee0b5 Doc/library/constants.rst --- a/Doc/library/constants.rst Sun Nov 23 16:01:20 2014 +0100 +++ b/Doc/library/constants.rst Sun Nov 23 08:07:41 2014 -0800 @@ -19,23 +19,36 @@ A small number of constants live in the .. data:: None The sole value of the type ``NoneType``. ``None`` is frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`. .. data:: NotImplemented - Special value which should be returned by the special methods - (:meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, etc.) to indicate - that the operation is not implemented with respect to the other type. + Special value which should be returned by the binary special methods + (e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`, + etc.) to indicate that the operation is not implemented with respect to + the other type; may be returned by the in-place binary special methods + (e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose. + Its truth value is true. + + Note:: + When NotImplemented is returned, the interpreter will then try the + reflected operation on the other type, or some other fallback, depending + on the operator. If all attempted operations return NotImplemented, the + interpreter will raise an appropriate exception. + + See + :ref:`Implementing the arithmetic operations ` + for more details. .. data:: Ellipsis The same as ``...``. Special value used mostly in conjunction with extended slicing syntax for user-defined container data types. .. data:: __debug__ diff -r dfe7d9fee0b5 Doc/library/numbers.rst --- a/Doc/library/numbers.rst Sun Nov 23 16:01:20 2014 +0100 +++ b/Doc/library/numbers.rst Sun Nov 23 08:07:41 2014 -0800 @@ -103,20 +103,22 @@ Adding More Numeric ABCs There are, of course, more possible ABCs for numbers, and this would be a poor hierarchy if it precluded the possibility of adding those. You can add ``MyFoo`` between :class:`Complex` and :class:`Real` with:: class MyFoo(Complex): ... MyFoo.register(Real) +.. _implementing-the-arithmetic-operations: + Implementing the arithmetic operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We want to implement the arithmetic operations so that mixed-mode operations either call an implementation whose author knew about the types of both arguments, or convert both to the nearest built in type and do the operation there. For subtypes of :class:`Integral`, this means that :meth:`__add__` and :meth:`__radd__` should be defined as:: class MyIntegral(Integral): diff -r dfe7d9fee0b5 Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst Sun Nov 23 16:01:20 2014 +0100 +++ b/Doc/reference/datamodel.rst Sun Nov 23 08:07:41 2014 -0800 @@ -147,24 +147,29 @@ None This type has a single value. There is a single object with this value. This object is accessed through the built-in name ``None``. It is used to signify the absence of a value in many situations, e.g., it is returned from functions that don't explicitly return anything. Its truth value is false. NotImplemented .. index:: object: NotImplemented This type has a single value. There is a single object with this value. This object is accessed through the built-in name ``NotImplemented``. Numeric methods - and rich comparison methods may return this value if they do not implement the + and rich comparison methods should return this value if they do not implement the operation for the operands provided. (The interpreter will then try the reflected operation, or some other fallback, depending on the operator.) Its truth value is true. + + See + :ref:`Implementing the arithmetic operations ` + for more details. + Ellipsis .. index:: object: Ellipsis This type has a single value. There is a single object with this value. This object is accessed through the literal ``...`` or the built-in name ``Ellipsis``. Its truth value is true. :class:`numbers.Number` .. index:: object: numeric