Expression can be simplified on list

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Wed Sep 14 18:46:04 EDT 2016


On Thursday, September 15, 2016 at 9:12:25 AM UTC+12, Ned Batchelder wrote:
>
> 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.

“Conversion method” versus ”explicit conversion” are two different things. The class provided a method to convert to bool, but Python itself does automatic interpretation of non-boolean values as booleans. It is the latter I am objecting to.



More information about the Python-list mailing list