[Python-ideas] Please reconsider the Boolean evaluation of midnight
Alexander Belopolsky
alexander.belopolsky at gmail.com
Thu Mar 6 17:13:57 CET 2014
More information about the Python-ideas mailing list
Thu Mar 6 17:13:57 CET 2014
- Previous message: [Python-ideas] Please reconsider the Boolean evaluation of midnight
- Next message: [Python-ideas] Please reconsider the Boolean evaluation of midnight
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Mar 6, 2014 at 8:21 AM, M.-A. Lemburg <mal at egenix.com> wrote: > > 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. FWIW, I would be +0 for making a change so that t.tzinfo is not None implies bool(t.timetz()) is True. My intuition goes like this. Given >>> from datetime import * >>> t1 = datetime(2014, 1, 1) >>> t2 = datetime(2014, 1, 1, 12) >>> t3 = datetime(2014, 1, 1, tzinfo=timezone.utc) Instance t1 has no time information, so t1.time() is false-y. Instance t2 has time information, so t2.time() is true-y. Instance t3 is such that t3.time() == t1.time(), but t3.timetz() has an additional information >>> t3.timetz() datetime.time(0, 0, tzinfo=datetime.timezone.utc) >>> t3.time() datetime.time(0, 0) So t3.timetz() is not the same object as returned by the constructor with no arguments - time(). This is reason enough to make it true-y. This also does not affect my use-case because t3.time() is still false-y in this logic: >>> [bool(t) for t in [t1.time(), t2.time(), t3.time(), time()]] [False, True, False, False] Which is consistent with >>> t3.time() == t1.time() == time() True -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/9f1b8972/attachment-0001.html>
- Previous message: [Python-ideas] Please reconsider the Boolean evaluation of midnight
- Next message: [Python-ideas] Please reconsider the Boolean evaluation of midnight
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list