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

Paul Moore p.f.moore at gmail.com
Wed Mar 5 16:37:14 CET 2014


On 5 March 2014 15:19, Shai Berger <shai at platonix.com> wrote:
> What, other than "bug", do you call behavior that isn't sensible?

"Unfortunate". I'm not arguing that the behaviour is useful. Or
sensible. What I'm arguing, and you're missing, is that the behaviour
is as documented, and so can't be changed without backward
compatibility implications. Specifically, see
http://docs.python.org/3.4/library/datetime.html#time-objects:

"""in Boolean contexts, a time object is considered to be true if and
only if, after converting it to minutes and subtracting utcoffset()
(or 0 if that's None), the result is non-zero."""

Your code is ignoring documented behaviour. Worse, your code can
clearly be improved by being explicit in your test, and yet you'd
rather argue that the Python developers implement a backward
compatibility break which you won't even be able to take advantage of
until you drop support of versions of Python before 3.7.

Paul.


More information about the Python-ideas mailing list