Here's a patch that adds dead code elimination for if 0: style statements, and improves the current dead code elimination for while statements by not performing elimination if the function is a generator. If the last yield statement from a generator is removed, the generator is turned into a regular function, which changes the semantics of the function.
Logged In: YES user_id=849994 Attaching new patch which does elimination for if 0, if 1 and if __debug__ correctly (visiting else clauses!) and correctly recognizes functions mixing "return x" and "yield".
Logged In: YES user_id=357491 Replied on python-dev, but for thoroughness, the patch looks fine from looking at the patch file itself. Apply the 'return' detection on its own, though, for better tracking of changes and easier rollback if something does go bad.
Logged In: YES user_id=33168 It would be nice to make a #define for the error message so they don't get out of sync. I wouldn't mind seeing the variable name spelled out, ste_returns_value or something like that. I didn't look closely at the line numbers and verify the changes were correct.