Index: Python/compile.c =================================================================== --- Python/compile.c.orig 2008-01-24 17:19:55.148321400 +0100 +++ Python/compile.c 2008-01-24 17:28:13.663317600 +0100 @@ -1735,8 +1735,11 @@ basicblock *loop, *orelse, *end, *anchor = NULL; int constant = expr_constant(s->v.While.test); - if (constant == 0) + if (constant == 0) { + if (s->v.While.orelse) + VISIT_SEQ(c, stmt, s->v.While.orelse); return 1; + } loop = compiler_new_block(c); end = compiler_new_block(c); if (constant == -1) { Index: Lib/test/test_grammar.py =================================================================== --- Lib/test/test_grammar.py.orig 2008-01-24 17:25:29.496728100 +0100 +++ Lib/test/test_grammar.py 2008-01-24 17:31:00.033019200 +0100 @@ -498,6 +498,15 @@ while 0: pass else: pass + # Issue1920: "while 0" is optimized away, + # ensure that the "else" clause is still present. + x = 0 + while 0: + x = 1 + else: + x = 2 + self.assertEquals(x, 2) + def testFor(self): # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] for i in 1, 2, 3: pass