diff options
author | MojoVampire <shadowranger+github@gmail.com> | 2020-03-03 18:50:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-03 18:50:17 (GMT) |
commit | 469325c30e147680543b2f5118b83fd95055a499 (patch) | |
tree | c10fd8f26059cb0e6caef9a7c081d324e4146969 /Doc | |
parent | ae75a294352e9b9487f5dc8e88f068e7e6974dc2 (diff) | |
download | cpython-469325c30e147680543b2f5118b83fd95055a499.zip cpython-469325c30e147680543b2f5118b83fd95055a499.tar.gz cpython-469325c30e147680543b2f5118b83fd95055a499.tar.bz2 |
bpo-35712: Make using NotImplemented in a boolean context issue a deprecation warning (GH-13195)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/constants.rst | 7 | ||||
-rw-r--r-- | Doc/reference/datamodel.rst | 9 | ||||
-rw-r--r-- | Doc/whatsnew/3.9.rst | 6 |
3 files changed, 19 insertions, 3 deletions
diff --git a/Doc/library/constants.rst b/Doc/library/constants.rst index 5017159..f17e1a3 100644 --- a/Doc/library/constants.rst +++ b/Doc/library/constants.rst @@ -31,7 +31,7 @@ A small number of constants live in the built-in namespace. They are: 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. + It should not be evaluated in a boolean context. .. note:: @@ -50,6 +50,11 @@ A small number of constants live in the built-in namespace. They are: even though they have similar names and purposes. See :exc:`NotImplementedError` for details on when to use it. + .. versionchanged:: 3.9 + Evaluating ``NotImplemented`` in a boolean context is deprecated. While + it currently evaluates as true, it will emit a :exc:`DeprecationWarning`. + It will raise a :exc:`TypeError` in a future version of Python. + .. index:: single: ...; ellipsis literal .. data:: Ellipsis diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 5b3b669..8be432d 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -156,13 +156,18 @@ NotImplemented object is accessed through the built-in name ``NotImplemented``. Numeric methods 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. + reflected operation, or some other fallback, depending on the operator.) It + should not be evaluated in a boolean context. See :ref:`implementing-the-arithmetic-operations` for more details. + .. versionchanged:: 3.9 + Evaluating ``NotImplemented`` in a boolean context is deprecated. While + it currently evaluates as true, it will emit a :exc:`DeprecationWarning`. + It will raise a :exc:`TypeError` in a future version of Python. + Ellipsis .. index:: diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index f49575d..9a8a484 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -452,6 +452,12 @@ Deprecated of Python. For the majority of use cases, users can leverage the Abstract Syntax Tree (AST) generation and compilation stage, using the :mod:`ast` module. +* Using :data:`NotImplemented` in a boolean context has been deprecated, + as it is almost exclusively the result of incorrect rich comparator + implementations. It will be made a :exc:`TypeError` in a future version + of Python. + (Contributed by Josh Rosenberg in :issue:`35712`.) + * The :mod:`random` module currently accepts any hashable type as a possible seed value. Unfortunately, some of those types are not guaranteed to have a deterministic hash value. After Python 3.9, |