@@ -66,6 +66,8 @@ def to_tuple(t):
6666 "if v:pass" ,
6767 # If-Elif
6868 "if a:\n pass\n elif b:\n pass" ,
69+ # If-Elif-Else
70+ "if a:\n pass\n elif b:\n pass\n else:\n pass" ,
6971 # With
7072 "with x as y: pass" ,
7173 "with x as y, z as q: pass" ,
@@ -606,6 +608,12 @@ def test_elif_stmt_start_position(self):
606608 self .assertEqual (elif_stmt .lineno , 3 )
607609 self .assertEqual (elif_stmt .col_offset , 0 )
608610
611+ def test_elif_stmt_start_position_with_else (self ):
612+ node = ast .parse ('if a:\n pass\n elif b:\n pass\n else:\n pass\n ' )
613+ elif_stmt = node .body [0 ].orelse [0 ]
614+ self .assertEqual (elif_stmt .lineno , 3 )
615+ self .assertEqual (elif_stmt .col_offset , 0 )
616+
609617 def test_literal_eval (self ):
610618 self .assertEqual (ast .literal_eval ('[1, 2, 3]' ), [1 , 2 , 3 ])
611619 self .assertEqual (ast .literal_eval ('{"foo": 42}' ), {"foo" : 42 })
@@ -1244,6 +1252,7 @@ def main():
12441252('Module' , [('While' , (1 , 0 ), ('Name' , (1 , 6 ), 'v' , ('Load' ,)), [('Pass' , (1 , 8 ))], [])]),
12451253('Module' , [('If' , (1 , 0 ), ('Name' , (1 , 3 ), 'v' , ('Load' ,)), [('Pass' , (1 , 5 ))], [])]),
12461254('Module' , [('If' , (1 , 0 ), ('Name' , (1 , 3 ), 'a' , ('Load' ,)), [('Pass' , (2 , 2 ))], [('If' , (3 , 0 ), ('Name' , (3 , 5 ), 'b' , ('Load' ,)), [('Pass' , (4 , 2 ))], [])])]),
1255+ ('Module' , [('If' , (1 , 0 ), ('Name' , (1 , 3 ), 'a' , ('Load' ,)), [('Pass' , (2 , 2 ))], [('If' , (3 , 0 ), ('Name' , (3 , 5 ), 'b' , ('Load' ,)), [('Pass' , (4 , 2 ))], [('Pass' , (6 , 2 ))])])]),
12471256('Module' , [('With' , (1 , 0 ), [('withitem' , ('Name' , (1 , 5 ), 'x' , ('Load' ,)), ('Name' , (1 , 10 ), 'y' , ('Store' ,)))], [('Pass' , (1 , 13 ))])]),
12481257('Module' , [('With' , (1 , 0 ), [('withitem' , ('Name' , (1 , 5 ), 'x' , ('Load' ,)), ('Name' , (1 , 10 ), 'y' , ('Store' ,))), ('withitem' , ('Name' , (1 , 13 ), 'z' , ('Load' ,)), ('Name' , (1 , 18 ), 'q' , ('Store' ,)))], [('Pass' , (1 , 21 ))])]),
12491258('Module' , [('Raise' , (1 , 0 ), ('Call' , (1 , 6 ), ('Name' , (1 , 6 ), 'Exception' , ('Load' ,)), [('Str' , (1 , 16 ), 'string' )], []), None )]),
0 commit comments