[Python-ideas] Please reconsider the Boolean evaluation of midnight

Andrew Barnert abarnert at yahoo.com
Thu Mar 6 20:01:16 CET 2014


On Mar 6, 2014, at 4:08, Nick Coghlan <ncoghlan at gmail.com> wrote:

> if x not in (naivemidnight, utcmidnight):
>        # This is the current bool(x)
>        ....
>   if x != naivemidnight:
>        # This has no current shorthand
>       ....
>    if x != utcmidnight:
>        # This has no current shorthand
>       ....
>    if x != localmidnight:
>        # This has no current shorthand
>        ....

This is a great argument. The problem here isn't that we use midnight as 0, but that naive and aware times are the same type and we use UTC midnight as 0 for aware types. The other languages/libraries/apps that treat midnight as 0 are generally either naive-only, or much more explicit about awareness.

Since that isn't going to change in Python, maybe it would be better to provide these values (or functions that return them) as names in the module, and explicitly encourage testing against them in place of bool testing, and define bool testing exactly like this, whether or not it's deprecated?


More information about the Python-ideas mailing list