[Python-ideas] bool(datetime.time(0, 0))

Nick Coghlan ncoghlan at gmail.com
Tue May 8 03:57:08 CEST 2012


On Tue, May 8, 2012 at 10:32 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> M.-A. Lemburg wrote:
>>
>> In Python 3.x, nb_nonzero was renamed to nb_bool without really
>> paying attention to the fact that many types implemented the original
>> meaning instead of a notion of boolean value
>
>
> I don't think it was wrong to do that. The fact that the
> C slot was called "nonzero" was never visible to the Python
> programmer, who always thought of the operation it represents
> as truth-testing.
>
> If there's any fault here, it's with C type implementors who
> have taken "nonzero" too literally.

The Python level special method in 2.x is also __nonzero__ (or you
could just implement __len__).

In 3.x, the two relevant special methods are now __bool__ and __len__.
Type designers are, of course, still free to use "non-zero" as their
definition for how they choose to implement __bool__.

For myself, I don't see any harm in having the zero hour be treated as
the zero hour at the language level ("zero hour" is another term for
midnight, which, as far as I know, stems from the military Zulu
notation where it's written as "0000Z"). Certainly I don't see
adequate justification for changing the boolean behaviour of time
objects at this late date.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list