Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would `if False` execute in Python?

Tags:

python

While browsing some code, I came across this line:

if False: #shedskin

I understand that Shedskin is a kind of Python -> C++ compiler, but I can't understand that line.

Shouldn't if False: never execute? What's going on here?

For context:

This is the whole block:

if False: # shedskin
    AStar(SQ_MapHandler([1], 1, 1)).findPath(SQ_Location(1,1), SQ_Location(1,1))

More context is on Google Code (scroll down all the way).

like image 379
John Avatar asked Nov 29 '22 16:11

John


1 Answers

It won't execute, because it isn't supposed to. The if False: is there to intentionally prevent the next line from executing, because that code's only purpose is seemingly to help Shed Skin infer type information about the argument to the AStar() function.

You can see another example of this in httplib:

#   Useless stuff to help type info
if False :
    conn._set_tunnel("example.com")
like image 72
Tim Stone Avatar answered Dec 06 '22 00:12

Tim Stone