[Python-ideas] Please reconsider the Boolean evaluation of midnight
Stephen J. Turnbull
stephen at xemacs.org
Thu Mar 6 15:33:10 CET 2014
M.-A. Lemburg writes:
> > Are they all False? No, no they're not (unless your local timezone is UTC):
> >
> >>>> bool(utcmidnight)
> > False
> >>>> bool(naivemidnight)
> > False
> >>>> bool(localmidnight)
> > True
>
> Now this is a what I consider a valid argument for making a change.
>
> Thanks, Nick.
I don't understand this turnabout. After all, time with time zones is
the temporal equivalent of ISO 2022. It's just madness encapsulated
in a formal data type definition.[1] Nobody should expect to get sane
results from manipulating that stuff, only hope to get lucky.
The only argument I've seen that corresponds to sane programming
practice is Nick's statement that in Python, None, zeros, and empty
containers are naturally false-ys, and all other objects are expected
to be truth-ys. I find *that* compelling, even though it is backward
incompatible with the documented behavior of time.time, and would not
affect code using time.time objects that was written in good style.
But I still don't like the way actually making the change would
validate using "if var:" where "if var is not None:" is appropriate.
I don't care if the change is made, but I hope it will be made
absolutely clear that it's purely to work around *old* bugs that may
never get fixed, and that "if var:" which is actually testing for
identity with a false-y sentinel is still strongly discouraged.
Footnotes:
[1] Time counted in seconds from an epoch is hard enough, just Google
for "monotonic clock". :-(
More information about the Python-ideas
mailing list