4444PYC_EXT = ".py" + (__debug__ and "c" or "o" )
4545PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
4646
47- if sys .version_info >= (3 , 5 ):
48- ast_Call = ast .Call
49- else :
50-
51- def ast_Call (a , b , c ):
52- return ast .Call (a , b , c , None , None )
53-
5447
5548class AssertionRewritingHook (object ):
5649 """PEP302 Import hook which rewrites asserts."""
@@ -702,7 +695,7 @@ def helper(self, name, *args):
702695 """Call a helper in this module."""
703696 py_name = ast .Name ("@pytest_ar" , ast .Load ())
704697 attr = ast .Attribute (py_name , name , ast .Load ())
705- return ast_Call (attr , list (args ), [])
698+ return ast . Call (attr , list (args ), [])
706699
707700 def builtin (self , name ):
708701 """Return the builtin called *name*."""
@@ -812,7 +805,7 @@ def visit_Assert(self, assert_):
812805 msg = self .pop_format_context (template )
813806 fmt = self .helper ("_format_explanation" , msg )
814807 err_name = ast .Name ("AssertionError" , ast .Load ())
815- exc = ast_Call (err_name , [fmt ], [])
808+ exc = ast . Call (err_name , [fmt ], [])
816809 raise_ = ast .Raise (exc , None )
817810
818811 body .append (raise_ )
@@ -856,7 +849,7 @@ def warn_about_none_ast(self, node, module_path, lineno):
856849 def visit_Name (self , name ):
857850 # Display the repr of the name if it's a local variable or
858851 # _should_repr_global_name() thinks it's acceptable.
859- locs = ast_Call (self .builtin ("locals" ), [], [])
852+ locs = ast . Call (self .builtin ("locals" ), [], [])
860853 inlocs = ast .Compare (ast .Str (name .id ), [ast .In ()], [locs ])
861854 dorepr = self .helper ("_should_repr_global_name" , name )
862855 test = ast .BoolOp (ast .Or (), [inlocs , dorepr ])
@@ -883,7 +876,7 @@ def visit_BoolOp(self, boolop):
883876 res , expl = self .visit (v )
884877 body .append (ast .Assign ([ast .Name (res_var , ast .Store ())], res ))
885878 expl_format = self .pop_format_context (ast .Str (expl ))
886- call = ast_Call (app , [expl_format ], [])
879+ call = ast . Call (app , [expl_format ], [])
887880 self .on_failure .append (ast .Expr (call ))
888881 if i < levels :
889882 cond = res
@@ -912,9 +905,9 @@ def visit_BinOp(self, binop):
912905 res = self .assign (ast .BinOp (left_expr , binop .op , right_expr ))
913906 return res , explanation
914907
915- def visit_Call_35 (self , call ):
908+ def visit_Call (self , call ):
916909 """
917- visit `ast.Call` nodes on Python3.5 and after
910+ visit `ast.Call` nodes
918911 """
919912 if isinstance (call .func , ast .Name ) and call .func .id == "all" :
920913 return self ._visit_all (call )
@@ -968,46 +961,6 @@ def visit_Starred(self, starred):
968961 new_starred = ast .Starred (res , starred .ctx )
969962 return new_starred , "*" + expl
970963
971- def visit_Call_legacy (self , call ):
972- """
973- visit `ast.Call nodes on 3.4 and below`
974- """
975- if isinstance (call .func , ast .Name ) and call .func .id == "all" :
976- return self ._visit_all (call )
977- new_func , func_expl = self .visit (call .func )
978- arg_expls = []
979- new_args = []
980- new_kwargs = []
981- new_star = new_kwarg = None
982- for arg in call .args :
983- res , expl = self .visit (arg )
984- new_args .append (res )
985- arg_expls .append (expl )
986- for keyword in call .keywords :
987- res , expl = self .visit (keyword .value )
988- new_kwargs .append (ast .keyword (keyword .arg , res ))
989- arg_expls .append (keyword .arg + "=" + expl )
990- if call .starargs :
991- new_star , expl = self .visit (call .starargs )
992- arg_expls .append ("*" + expl )
993- if call .kwargs :
994- new_kwarg , expl = self .visit (call .kwargs )
995- arg_expls .append ("**" + expl )
996- expl = "%s(%s)" % (func_expl , ", " .join (arg_expls ))
997- new_call = ast .Call (new_func , new_args , new_kwargs , new_star , new_kwarg )
998- res = self .assign (new_call )
999- res_expl = self .explanation_param (self .display (res ))
1000- outer_expl = "%s\n {%s = %s\n }" % (res_expl , res_expl , expl )
1001- return res , outer_expl
1002-
1003- # ast.Call signature changed on 3.5,
1004- # conditionally change which methods is named
1005- # visit_Call depending on Python version
1006- if sys .version_info >= (3 , 5 ):
1007- visit_Call = visit_Call_35
1008- else :
1009- visit_Call = visit_Call_legacy
1010-
1011964 def visit_Attribute (self , attr ):
1012965 if not isinstance (attr .ctx , ast .Load ):
1013966 return self .generic_visit (attr )
0 commit comments