[issue35712] Make NotImplemented unusable in boolean context
Guido van Rossum
report at bugs.python.org
Fri Jan 11 11:07:42 EST 2019
Guido van Rossum <guido at python.org> added the comment:
I agree.
On Thu, Jan 10, 2019 at 11:24 PM Serhiy Storchaka <report at bugs.python.org>
wrote:
>
> Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
>
> This is a common mistake. Even the default implementation of object.__ne__
> had a bug, fixed only 4 years ago in issue21408. There were several errors
> in stdlib. I am sure there is a lot of occurrences of this errors in a
> third party code.
>
> So I like this idea. This can help to fix hidden errors in existing code.
> But I share also Josh's concerns.
>
> There is related common mistake. In C code, the result of
> PyObject_IsTrue() often is treated as just a boolean, without checking for
> errors. Fortunately, in the current CPython code it is handled properly,
> but I am sure this error still is occurred in third-party extensions.
>
> When these two errors (using NotImplemented in the boolean context and
> ignoring the error in PyObject_IsTrue() in the C code) meet, this can lead
> to manifestation of more weird bugs than treating NotImplemented as true:
> from a crash in debug build to raising an exception in the following
> unrelated code.
>
> I suggest to start emitting a DeprecationWarning or a FutureWarning in
> NotImplemented.__bool__.
>
> ----------
> nosy: +gvanrossum, serhiy.storchaka
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue35712>
> _______________________________________
>
--
--Guido (mobile)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35712>
_______________________________________
More information about the Python-bugs-list
mailing list