@@ -3153,14 +3153,6 @@ def test_folding_binop(self):
31533153 ):
31543154 self .assert_ast (result_code , non_optimized_target , optimized_target )
31553155
3156- # Tuple folding is currently disabled in the AST optimizer
3157- # Multiplication of constant tuples must be folded
3158- # code = "(1,) * 3"
3159- # non_optimized_target = self.wrap_expr(self.create_binop("*", ast.Tuple(elts=[ast.Constant(value=1)]), ast.Constant(value=3)))
3160- # optimized_target = self.wrap_expr(ast.Constant(eval(code)))
3161-
3162- # self.assert_ast(code, non_optimized_target, optimized_target)
3163-
31643156 def test_folding_unaryop (self ):
31653157 code = "%s1"
31663158 operators = self .unaryop .keys ()
@@ -3180,39 +3172,6 @@ def create_unaryop(operand):
31803172 ):
31813173 self .assert_ast (result_code , non_optimized_target , optimized_target )
31823174
3183- @unittest .skip ("Tuple folding is currently disabled in the AST optimizer" )
3184- def test_folding_not (self ):
3185- code = "not (1 %s (1,))"
3186- operators = {
3187- "in" : ast .In (),
3188- "is" : ast .Is (),
3189- }
3190- opt_operators = {
3191- "is" : ast .IsNot (),
3192- "in" : ast .NotIn (),
3193- }
3194-
3195- def create_notop (operand ):
3196- return ast .UnaryOp (op = ast .Not (), operand = ast .Compare (
3197- left = ast .Constant (value = 1 ),
3198- ops = [operators [operand ]],
3199- comparators = [ast .Tuple (elts = [ast .Constant (value = 1 )])]
3200- ))
3201-
3202- for op in operators .keys ():
3203- result_code = code % op
3204- non_optimized_target = self .wrap_expr (create_notop (op ))
3205- optimized_target = self .wrap_expr (
3206- ast .Compare (left = ast .Constant (1 ), ops = [opt_operators [op ]], comparators = [ast .Constant (value = (1 ,))])
3207- )
3208-
3209- with self .subTest (
3210- result_code = result_code ,
3211- non_optimized_target = non_optimized_target ,
3212- optimized_target = optimized_target
3213- ):
3214- self .assert_ast (result_code , non_optimized_target , optimized_target )
3215-
32163175 def test_folding_format (self ):
32173176 code = "'%s' % (a,)"
32183177
@@ -3232,15 +3191,6 @@ def test_folding_format(self):
32323191
32333192 self .assert_ast (code , non_optimized_target , optimized_target )
32343193
3235- @unittest .skip ("Tuple folding is currently disabled in the AST optimizer" )
3236- def test_folding_tuple (self ):
3237- code = "(1,)"
3238-
3239- non_optimized_target = self .wrap_expr (ast .Tuple (elts = [ast .Constant (1 )]))
3240- optimized_target = self .wrap_expr (ast .Constant (value = (1 ,)))
3241-
3242- self .assert_ast (code , non_optimized_target , optimized_target )
3243-
32443194 def test_folding_comparator (self ):
32453195 code = "1 %s %s1%s"
32463196 operators = [("in" , ast .In ()), ("not in" , ast .NotIn ())]
@@ -3281,15 +3231,15 @@ def test_folding_iter(self):
32813231
32823232 self .assert_ast (code % (left , right ), non_optimized_target , optimized_target )
32833233
3284- @unittest .skip ("Tuple folding is currently disabled in the AST optimizer" )
32853234 def test_folding_subscript (self ):
3286- code = "(1,) [0]"
3235+ code = "'abcd' [0]"
32873236
32883237 non_optimized_target = self .wrap_expr (
3289- ast .Subscript (value = ast .Tuple (elts = [ast .Constant (value = 1 )]), slice = ast .Constant (value = 0 ))
3238+ ast .Subscript (value = ast .Constant (value = 'abcd' ), slice = ast .Constant (value = 0 ))
3239+ )
3240+ optimized_target = self .wrap_expr (
3241+ ast .JoinedStr (values = [ast .Constant (value = 'a' )])
32903242 )
3291- optimized_target = self .wrap_expr (ast .Constant (value = 1 ))
3292-
32933243 self .assert_ast (code , non_optimized_target , optimized_target )
32943244
32953245 def test_folding_type_param_in_function_def (self ):
0 commit comments