@@ -180,36 +180,20 @@ def to_tuple(t):
180180
181181class AST_Tests (unittest .TestCase ):
182182
183- def _assertTrueorder (self , ast_node , parent_pos , reverse_check = False ):
184- def should_reverse_check (parent , child ):
185- # In some situations, the children of nodes occur before
186- # their parents, for example in a.b.c, a occurs before b
187- # but a is a child of b.
188- if isinstance (parent , ast .Call ):
189- if parent .func == child :
190- return True
191- if isinstance (parent , (ast .Attribute , ast .Subscript )):
192- return True
193- return False
194-
183+ def _assertTrueorder (self , ast_node , parent_pos ):
195184 if not isinstance (ast_node , ast .AST ) or ast_node ._fields is None :
196185 return
197186 if isinstance (ast_node , (ast .expr , ast .stmt , ast .excepthandler )):
198187 node_pos = (ast_node .lineno , ast_node .col_offset )
199- if reverse_check :
200- self .assertTrue (node_pos <= parent_pos )
201- else :
202- self .assertTrue (node_pos >= parent_pos )
188+ self .assertTrue (node_pos >= parent_pos )
203189 parent_pos = (ast_node .lineno , ast_node .col_offset )
204190 for name in ast_node ._fields :
205191 value = getattr (ast_node , name )
206192 if isinstance (value , list ):
207193 for child in value :
208- self ._assertTrueorder (child , parent_pos ,
209- should_reverse_check (ast_node , child ))
194+ self ._assertTrueorder (child , parent_pos )
210195 elif value is not None :
211- self ._assertTrueorder (value , parent_pos ,
212- should_reverse_check (ast_node , value ))
196+ self ._assertTrueorder (value , parent_pos )
213197
214198 def test_AST_objects (self ):
215199 x = ast .AST ()
@@ -278,9 +262,8 @@ def test_field_attr_existence(self):
278262
279263 def test_arguments (self ):
280264 x = ast .arguments ()
281- self .assertEqual (x ._fields , ('args' , 'vararg' ,
282- 'kwonlyargs' , 'kw_defaults' ,
283- 'kwarg' , 'defaults' ))
265+ self .assertEqual (x ._fields , ('args' , 'vararg' , 'kwonlyargs' ,
266+ 'kw_defaults' , 'kwarg' , 'defaults' ))
284267
285268 with self .assertRaises (AttributeError ):
286269 x .vararg
@@ -455,7 +438,7 @@ def test_dump(self):
455438 "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), "
456439 "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, "
457440 "col_offset=11)], keywords=[], starargs=None, kwargs=None, "
458- "lineno=1, col_offset=4 ), lineno=1, col_offset=0)])"
441+ "lineno=1, col_offset=0 ), lineno=1, col_offset=0)])"
459442 )
460443
461444 def test_copy_location (self ):
@@ -476,7 +459,7 @@ def test_fix_missing_locations(self):
476459 "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), "
477460 "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, "
478461 "col_offset=6)], keywords=[], starargs=None, kwargs=None, "
479- "lineno=1, col_offset=5 ), lineno=1, col_offset=0), "
462+ "lineno=1, col_offset=0 ), lineno=1, col_offset=0), "
480463 "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, "
481464 "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], "
482465 "keywords=[], starargs=None, kwargs=None, lineno=1, "
@@ -973,7 +956,7 @@ def main():
973956('Module' , [('FunctionDef' , (1 , 0 ), 'f' , ('arguments' , [('arg' , (1 , 6 ), 'a' , None )], None , [], [], None , [('Num' , (1 , 8 ), 0 )]), [('Pass' , (1 , 12 ))], [], None )]),
974957('Module' , [('FunctionDef' , (1 , 0 ), 'f' , ('arguments' , [], ('arg' , (1 , 7 ), 'args' , None ), [], [], None , []), [('Pass' , (1 , 14 ))], [], None )]),
975958('Module' , [('FunctionDef' , (1 , 0 ), 'f' , ('arguments' , [], None , [], [], ('arg' , (1 , 8 ), 'kwargs' , None ), []), [('Pass' , (1 , 17 ))], [], None )]),
976- ('Module' , [('FunctionDef' , (1 , 0 ), 'f' , ('arguments' , [('arg' , (1 , 6 ), 'a' , None ), ('arg' , (1 , 9 ), 'b' , None ), ('arg' , (1 , 14 ), 'c' , None ), ('arg' , (1 , 22 ), 'd' , None ), ('arg' , (1 , 28 ), 'e' , None )], ('arg' , (1 , 35 ), 'args' , None ), [('arg' , (1 , 41 ), 'f' , None )], [('Num' , (1 , 43 ), 42 )], ('arg' , (1 , 49 ), 'kwargs' , None ), [('Num' , (1 , 11 ), 1 ), ('NameConstant' , (1 , 16 ), None ), ('List' , (1 , 24 ), [], ('Load' ,)), ('Dict' , (1 , 30 ), [], [])]), [('Pass' , (1 , 58 ))], [], None )]),
959+ ('Module' , [('FunctionDef' , (1 , 0 ), 'f' , ('arguments' , [('arg' , (1 , 6 ), 'a' , None ), ('arg' , (1 , 9 ), 'b' , None ), ('arg' , (1 , 14 ), 'c' , None ), ('arg' , (1 , 22 ), 'd' , None ), ('arg' , (1 , 28 ), 'e' , None )], ('arg' , (1 , 35 ), 'args' , None ), [('arg' , (1 , 41 ), 'f' , None )], [('Num' , (1 , 43 ), 42 )], ('arg' , (1 , 49 ), 'kwargs' , None ), [('Num' , (1 , 11 ), 1 ), ('NameConstant' , (1 , 16 ), None ), ('List' , (1 , 24 ), [], ('Load' ,)), ('Dict' , (1 , 30 ), [], [])]), [('Pass' , (1 , 58 ))], [], None )]),
977960('Module' , [('ClassDef' , (1 , 0 ), 'C' , [], [], None , None , [('Pass' , (1 , 8 ))], [])]),
978961('Module' , [('ClassDef' , (1 , 0 ), 'C' , [('Name' , (1 , 8 ), 'object' , ('Load' ,))], [], None , None , [('Pass' , (1 , 17 ))], [])]),
979962('Module' , [('FunctionDef' , (1 , 0 ), 'f' , ('arguments' , [], None , [], [], None , []), [('Return' , (1 , 8 ), ('Num' , (1 , 15 ), 1 ))], [], None )]),
@@ -985,7 +968,7 @@ def main():
985968('Module' , [('If' , (1 , 0 ), ('Name' , (1 , 3 ), 'v' , ('Load' ,)), [('Pass' , (1 , 5 ))], [])]),
986969('Module' , [('With' , (1 , 0 ), [('withitem' , ('Name' , (1 , 5 ), 'x' , ('Load' ,)), ('Name' , (1 , 10 ), 'y' , ('Store' ,)))], [('Pass' , (1 , 13 ))])]),
987970('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 ))])]),
988- ('Module' , [('Raise' , (1 , 0 ), ('Call' , (1 , 15 ), ('Name' , (1 , 6 ), 'Exception' , ('Load' ,)), [('Str' , (1 , 16 ), 'string' )], [], None , None ), None )]),
971+ ('Module' , [('Raise' , (1 , 0 ), ('Call' , (1 , 6 ), ('Name' , (1 , 6 ), 'Exception' , ('Load' ,)), [('Str' , (1 , 16 ), 'string' )], [], None , None ), None )]),
989972('Module' , [('Try' , (1 , 0 ), [('Pass' , (2 , 2 ))], [('ExceptHandler' , (3 , 0 ), ('Name' , (3 , 7 ), 'Exception' , ('Load' ,)), None , [('Pass' , (4 , 2 ))])], [], [])]),
990973('Module' , [('Try' , (1 , 0 ), [('Pass' , (2 , 2 ))], [], [], [('Pass' , (4 , 2 ))])]),
991974('Module' , [('Assert' , (1 , 0 ), ('Name' , (1 , 7 ), 'v' , ('Load' ,)), None )]),
@@ -1022,17 +1005,17 @@ def main():
10221005('Expression' , ('ListComp' , (1 , 1 ), ('Name' , (1 , 1 ), 'a' , ('Load' ,)), [('comprehension' , ('Name' , (1 , 7 ), 'b' , ('Store' ,)), ('Name' , (1 , 12 ), 'c' , ('Load' ,)), [('Name' , (1 , 17 ), 'd' , ('Load' ,))])])),
10231006('Expression' , ('GeneratorExp' , (1 , 1 ), ('Name' , (1 , 1 ), 'a' , ('Load' ,)), [('comprehension' , ('Name' , (1 , 7 ), 'b' , ('Store' ,)), ('Name' , (1 , 12 ), 'c' , ('Load' ,)), [('Name' , (1 , 17 ), 'd' , ('Load' ,))])])),
10241007('Expression' , ('Compare' , (1 , 0 ), ('Num' , (1 , 0 ), 1 ), [('Lt' ,), ('Lt' ,)], [('Num' , (1 , 4 ), 2 ), ('Num' , (1 , 8 ), 3 )])),
1025- ('Expression' , ('Call' , (1 , 1 ), ('Name' , (1 , 0 ), 'f' , ('Load' ,)), [('Num' , (1 , 2 ), 1 ), ('Num' , (1 , 4 ), 2 )], [('keyword' , 'c' , ('Num' , (1 , 8 ), 3 ))], ('Name' , (1 , 11 ), 'd' , ('Load' ,)), ('Name' , (1 , 15 ), 'e' , ('Load' ,)))),
1008+ ('Expression' , ('Call' , (1 , 0 ), ('Name' , (1 , 0 ), 'f' , ('Load' ,)), [('Num' , (1 , 2 ), 1 ), ('Num' , (1 , 4 ), 2 )], [('keyword' , 'c' , ('Num' , (1 , 8 ), 3 ))], ('Name' , (1 , 11 ), 'd' , ('Load' ,)), ('Name' , (1 , 15 ), 'e' , ('Load' ,)))),
10261009('Expression' , ('Num' , (1 , 0 ), 10 )),
10271010('Expression' , ('Str' , (1 , 0 ), 'string' )),
1028- ('Expression' , ('Attribute' , (1 , 2 ), ('Name' , (1 , 0 ), 'a' , ('Load' ,)), 'b' , ('Load' ,))),
1029- ('Expression' , ('Subscript' , (1 , 2 ), ('Name' , (1 , 0 ), 'a' , ('Load' ,)), ('Slice' , ('Name' , (1 , 2 ), 'b' , ('Load' ,)), ('Name' , (1 , 4 ), 'c' , ('Load' ,)), None ), ('Load' ,))),
1011+ ('Expression' , ('Attribute' , (1 , 0 ), ('Name' , (1 , 0 ), 'a' , ('Load' ,)), 'b' , ('Load' ,))),
1012+ ('Expression' , ('Subscript' , (1 , 0 ), ('Name' , (1 , 0 ), 'a' , ('Load' ,)), ('Slice' , ('Name' , (1 , 2 ), 'b' , ('Load' ,)), ('Name' , (1 , 4 ), 'c' , ('Load' ,)), None ), ('Load' ,))),
10301013('Expression' , ('Name' , (1 , 0 ), 'v' , ('Load' ,))),
10311014('Expression' , ('List' , (1 , 0 ), [('Num' , (1 , 1 ), 1 ), ('Num' , (1 , 3 ), 2 ), ('Num' , (1 , 5 ), 3 )], ('Load' ,))),
10321015('Expression' , ('List' , (1 , 0 ), [], ('Load' ,))),
10331016('Expression' , ('Tuple' , (1 , 0 ), [('Num' , (1 , 0 ), 1 ), ('Num' , (1 , 2 ), 2 ), ('Num' , (1 , 4 ), 3 )], ('Load' ,))),
10341017('Expression' , ('Tuple' , (1 , 1 ), [('Num' , (1 , 1 ), 1 ), ('Num' , (1 , 3 ), 2 ), ('Num' , (1 , 5 ), 3 )], ('Load' ,))),
10351018('Expression' , ('Tuple' , (1 , 0 ), [], ('Load' ,))),
1036- ('Expression' , ('Call' , (1 , 7 ), ('Attribute' , (1 , 6 ), ('Attribute' , (1 , 4 ), ('Attribute' , (1 , 2 ), ('Name' , (1 , 0 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), 'c' , ('Load' ,)), 'd' , ('Load' ,)), [('Subscript' , (1 , 12 ), ('Attribute' , (1 , 10 ), ('Name' , (1 , 8 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), ('Slice' , ('Num' , (1 , 12 ), 1 ), ('Num' , (1 , 14 ), 2 ), None ), ('Load' ,))], [], None , None )),
1019+ ('Expression' , ('Call' , (1 , 0 ), ('Attribute' , (1 , 0 ), ('Attribute' , (1 , 0 ), ('Attribute' , (1 , 0 ), ('Name' , (1 , 0 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), 'c' , ('Load' ,)), 'd' , ('Load' ,)), [('Subscript' , (1 , 8 ), ('Attribute' , (1 , 8 ), ('Name' , (1 , 8 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), ('Slice' , ('Num' , (1 , 12 ), 1 ), ('Num' , (1 , 14 ), 2 ), None ), ('Load' ,))], [], None , None )),
10371020]
10381021main ()
0 commit comments