@@ -343,6 +343,10 @@ def test_base_classes(self):
343343 def test_field_attr_existence (self ):
344344 for name , item in ast .__dict__ .items ():
345345 if self ._is_ast_node (name , item ):
346+ if name == 'Index' :
347+ # Index(value) just returns value now.
348+ # The argument is required.
349+ continue
346350 x = item ()
347351 if isinstance (x , ast .AST ):
348352 self .assertEqual (type (x ._fields ), tuple )
@@ -1308,21 +1312,21 @@ def test_attribute(self):
13081312 self .expr (attr , "must have Load context" )
13091313
13101314 def test_subscript (self ):
1311- sub = ast .Subscript (ast .Name ("x" , ast .Store ()), ast .Index ( ast . Num (3 ) ),
1315+ sub = ast .Subscript (ast .Name ("x" , ast .Store ()), ast .Num (3 ),
13121316 ast .Load ())
13131317 self .expr (sub , "must have Load context" )
13141318 x = ast .Name ("x" , ast .Load ())
1315- sub = ast .Subscript (x , ast .Index ( ast . Name ("y" , ast .Store () )),
1319+ sub = ast .Subscript (x , ast .Name ("y" , ast .Store ()),
13161320 ast .Load ())
13171321 self .expr (sub , "must have Load context" )
13181322 s = ast .Name ("x" , ast .Store ())
13191323 for args in (s , None , None ), (None , s , None ), (None , None , s ):
13201324 sl = ast .Slice (* args )
13211325 self .expr (ast .Subscript (x , sl , ast .Load ()),
13221326 "must have Load context" )
1323- sl = ast .ExtSlice ([])
1324- self .expr (ast .Subscript (x , sl , ast .Load ()), "empty dims on ExtSlice" )
1325- sl = ast .ExtSlice ([ ast .Index ( s )] )
1327+ sl = ast .Tuple ([], ast . Load () )
1328+ self .expr (ast .Subscript (x , sl , ast .Load ()))
1329+ sl = ast .Tuple ([ s ], ast .Load () )
13261330 self .expr (ast .Subscript (x , sl , ast .Load ()), "must have Load context" )
13271331
13281332 def test_starred (self ):
@@ -1664,11 +1668,11 @@ def test_slices(self):
16641668 ''' ).strip ()
16651669 i1 , i2 , im = map (self ._parse_value , (s1 , s2 , sm ))
16661670 self ._check_content (s1 , i1 .value , 'f()[1, 2]' )
1667- self ._check_content (s1 , i1 .value .slice . value , '1, 2' )
1671+ self ._check_content (s1 , i1 .value .slice , '1, 2' )
16681672 self ._check_content (s2 , i2 .slice .lower , 'a.b' )
16691673 self ._check_content (s2 , i2 .slice .upper , 'c.d' )
1670- self ._check_content (sm , im .slice .dims [0 ].upper , 'f ()' )
1671- self ._check_content (sm , im .slice .dims [1 ].lower , 'g ()' )
1674+ self ._check_content (sm , im .slice .elts [0 ].upper , 'f ()' )
1675+ self ._check_content (sm , im .slice .elts [1 ].lower , 'g ()' )
16721676 self ._check_end_pos (im , 3 , 3 )
16731677
16741678 def test_binop (self ):
@@ -1989,13 +1993,13 @@ def main():
19891993('Expression' , ('Constant' , (1 , 0 , 1 , 2 ), 10 , None )),
19901994('Expression' , ('Constant' , (1 , 0 , 1 , 8 ), 'string' , None )),
19911995('Expression' , ('Attribute' , (1 , 0 , 1 , 3 ), ('Name' , (1 , 0 , 1 , 1 ), 'a' , ('Load' ,)), 'b' , ('Load' ,))),
1992- ('Expression' , ('Subscript' , (1 , 0 , 1 , 6 ), ('Name' , (1 , 0 , 1 , 1 ), 'a' , ('Load' ,)), ('Slice' , ('Name' , (1 , 2 , 1 , 3 ), 'b' , ('Load' ,)), ('Name' , (1 , 4 , 1 , 5 ), 'c' , ('Load' ,)), None ), ('Load' ,))),
1996+ ('Expression' , ('Subscript' , (1 , 0 , 1 , 6 ), ('Name' , (1 , 0 , 1 , 1 ), 'a' , ('Load' ,)), ('Slice' , (1 , 2 , 1 , 5 ), ( 'Name' , (1 , 2 , 1 , 3 ), 'b' , ('Load' ,)), ('Name' , (1 , 4 , 1 , 5 ), 'c' , ('Load' ,)), None ), ('Load' ,))),
19931997('Expression' , ('Name' , (1 , 0 , 1 , 1 ), 'v' , ('Load' ,))),
19941998('Expression' , ('List' , (1 , 0 , 1 , 7 ), [('Constant' , (1 , 1 , 1 , 2 ), 1 , None ), ('Constant' , (1 , 3 , 1 , 4 ), 2 , None ), ('Constant' , (1 , 5 , 1 , 6 ), 3 , None )], ('Load' ,))),
19951999('Expression' , ('List' , (1 , 0 , 1 , 2 ), [], ('Load' ,))),
19962000('Expression' , ('Tuple' , (1 , 0 , 1 , 5 ), [('Constant' , (1 , 0 , 1 , 1 ), 1 , None ), ('Constant' , (1 , 2 , 1 , 3 ), 2 , None ), ('Constant' , (1 , 4 , 1 , 5 ), 3 , None )], ('Load' ,))),
19972001('Expression' , ('Tuple' , (1 , 0 , 1 , 7 ), [('Constant' , (1 , 1 , 1 , 2 ), 1 , None ), ('Constant' , (1 , 3 , 1 , 4 ), 2 , None ), ('Constant' , (1 , 5 , 1 , 6 ), 3 , None )], ('Load' ,))),
19982002('Expression' , ('Tuple' , (1 , 0 , 1 , 2 ), [], ('Load' ,))),
1999- ('Expression' , ('Call' , (1 , 0 , 1 , 17 ), ('Attribute' , (1 , 0 , 1 , 7 ), ('Attribute' , (1 , 0 , 1 , 5 ), ('Attribute' , (1 , 0 , 1 , 3 ), ('Name' , (1 , 0 , 1 , 1 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), 'c' , ('Load' ,)), 'd' , ('Load' ,)), [('Subscript' , (1 , 8 , 1 , 16 ), ('Attribute' , (1 , 8 , 1 , 11 ), ('Name' , (1 , 8 , 1 , 9 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), ('Slice' , ('Constant' , (1 , 12 , 1 , 13 ), 1 , None ), ('Constant' , (1 , 14 , 1 , 15 ), 2 , None ), None ), ('Load' ,))], [])),
2003+ ('Expression' , ('Call' , (1 , 0 , 1 , 17 ), ('Attribute' , (1 , 0 , 1 , 7 ), ('Attribute' , (1 , 0 , 1 , 5 ), ('Attribute' , (1 , 0 , 1 , 3 ), ('Name' , (1 , 0 , 1 , 1 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), 'c' , ('Load' ,)), 'd' , ('Load' ,)), [('Subscript' , (1 , 8 , 1 , 16 ), ('Attribute' , (1 , 8 , 1 , 11 ), ('Name' , (1 , 8 , 1 , 9 ), 'a' , ('Load' ,)), 'b' , ('Load' ,)), ('Slice' , (1 , 12 , 1 , 15 ), ( 'Constant' , (1 , 12 , 1 , 13 ), 1 , None ), ('Constant' , (1 , 14 , 1 , 15 ), 2 , None ), None ), ('Load' ,))], [])),
20002004]
20012005main ()
0 commit comments