User: Password:
Subscribe / Log in / New account

Re: Please reconsider the Boolean evaluation of midnight

From:  Paul Moore <>
To:  Masklinn <>
Subject:  Re: Please reconsider the Boolean evaluation of midnight
Date:  Wed, 5 Mar 2014 10:44:07 +0000
Message-ID:  <>
Cc:  Python-Ideas <>
Archive-link:  Article

On 5 March 2014 10:31, Masklinn <> wrote:
> Side-effect of e.g. an object with an optional (nullable) time field,
> the developer didn't realise a time could be false-ish (because
> seriously?) and then it turns out code along the lines of
>     if event.start_time:
>         # stuff
> unexpectedly fails if start_time is midnight.

Yeah, I was classing that as "application bug" and it's easy to fix
with an "is not None". Agreed that the odd behaviour of time in a
boolean context is why this whole class of bugs exists, but it's only
a subclass if the wider problem that people shouldn't truth-test
values without thinking - an explicit test is always better (explicit
is better than implicit and all that).

I actually find the idea of truth-testing a value that's expected to
have a type that is always true *more* unintuitive than an explicit
"is not None", so I'd fix the above code regardless of what the truth
value of midnight is.

Python-ideas mailing list
Code of Conduct:

(Log in to post comments)

Copyright © 2014, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds