Expression can be simplified on list
Ned Batchelder
ned at nedbatchelder.com
Wed Sep 14 17:12:04 EDT 2016
On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D’Oliveiro wrote:
> On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote:
> > Because True is the default, object need not and at least in CPython
> > does not have a __bool__ (or __len__) method.
>
> If they had to (in the absence of which a bool() cast would not work), then that would help prevent problems like the one I previously linked to, don’t you think?
Requiring an explicit conversion method wouldn't help the "midnight is False"
problem: it was *caused* by an explicit conversion method. From the article:
> A Python bug was opened in 2012 about midnight as False, but it was closed
> soon thereafter as "invalid". The time class was documented to work that way
> and someone had created a __nonzero__() (now __bool__()) method for time to
> implement that behavior.
--Ned.
More information about the Python-list
mailing list