11.03.20 12:39, Steven D'Aprano пише:
https://bugs.python.org/issue35712
I am disappointed because, to me, it is a fundamental part of Python's object model that *everything* can be interpreted as a truthy/falsey object (in the absence of bugs).
NotImplemented is special. It is more special than even None. It is special enough to break the rule. It's only purpose is to be a signal value for special methods like __add__ or __eq__, and errors related to interpreting it as boolean are pretty common (there was ones even in the stdlib). This is a clear case case of "Practicality beats purity." There is a precedence (although not in the stdlib): NumPy array with dtype=bool.
import numpy bool(numpy.array([False, False])) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()