# HG changeset patch # User Paul Boddie # Date 1548347980 -3600 # Node ID 6538a119a67f51f3d70b1d88a124bccad4096c76 # Parent 246c536e2d95d851b3a78bdca83caf8836e651a3 Added missing support for the else clause in for loops. diff -r 246c536e2d95 -r 6538a119a67f common.py --- a/common.py Thu Jan 17 18:26:05 2019 +0100 +++ b/common.py Thu Jan 24 17:39:40 2019 +0100 @@ -3,8 +3,8 @@ """ Common functions. -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, - 2014, 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, + 2017, 2018, 2019 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -582,7 +582,7 @@ # ... = () # ... # except StopIteration: - # pass + # {n.else_} compiler.ast.Assign( [compiler.ast.AssName(t2, "OP_ASSIGN")], @@ -600,7 +600,7 @@ )), n.body]), None), - [(compiler.ast.Name("StopIteration"), None, compiler.ast.Stmt([compiler.ast.Pass()]))], + [(compiler.ast.Name("StopIteration"), None, n.else_ or compiler.ast.Pass())], None) ]) diff -r 246c536e2d95 -r 6538a119a67f tests/for.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/for.py Thu Jan 24 17:39:40 2019 +0100 @@ -0,0 +1,16 @@ +l = [1, 2, 3] + +for i in l: + print i # 1 + # 2 + # 3 +else: + print 4 # 4 + +for i in l: + print i # 1 + # 2 + if i == 2: + break +else: + print 3