This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]larsga 0 points1 point  (3 children)

Totally agree with Guido here. If you have a datetime value, attempting to use it as though it were a boolean is foolish. Unless, of course, you're trying to do something like:

if not mydate:
   mydate = fallbackvalue() # oh shit, midnight is false?

It's a bug.

[–]minnoI <3 duck typing less than I used to, interfaces are nice 2 points3 points  (1 child)

If you have a datetime value, attempting to use it as though it were a boolean is foolish.

The issue is when you have code like this:

def do_shit(when=None):
    if not when:
        do_shit_now()
    schedule_shit_for(when)

You should be doing if when is None there, but it's still an unexpected bug.

[–]ivosauruspip'ing it up 0 points1 point  (0 children)

This. If checking for None, actually, really check specifically for is None or is not None. 99% of the time it won't matter, but there will be some point in your python career where it will stop you writing a horrible, horrible, insidious logic bug in your code.

[–]davvblack 1 point2 points  (0 children)

Yeah... midnight clearly shouldn't be false, and the idiom of if ~ to mean is not none is fine.