44
44
PYC_EXT = ".py" + (__debug__ and "c" or "o" )
45
45
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
46
46
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
-
54
47
55
48
class AssertionRewritingHook (object ):
56
49
"""PEP302 Import hook which rewrites asserts."""
@@ -702,7 +695,7 @@ def helper(self, name, *args):
702
695
"""Call a helper in this module."""
703
696
py_name = ast .Name ("@pytest_ar" , ast .Load ())
704
697
attr = ast .Attribute (py_name , name , ast .Load ())
705
- return ast_Call (attr , list (args ), [])
698
+ return ast . Call (attr , list (args ), [])
706
699
707
700
def builtin (self , name ):
708
701
"""Return the builtin called *name*."""
@@ -812,7 +805,7 @@ def visit_Assert(self, assert_):
812
805
msg = self .pop_format_context (template )
813
806
fmt = self .helper ("_format_explanation" , msg )
814
807
err_name = ast .Name ("AssertionError" , ast .Load ())
815
- exc = ast_Call (err_name , [fmt ], [])
808
+ exc = ast . Call (err_name , [fmt ], [])
816
809
raise_ = ast .Raise (exc , None )
817
810
818
811
body .append (raise_ )
@@ -856,7 +849,7 @@ def warn_about_none_ast(self, node, module_path, lineno):
856
849
def visit_Name (self , name ):
857
850
# Display the repr of the name if it's a local variable or
858
851
# _should_repr_global_name() thinks it's acceptable.
859
- locs = ast_Call (self .builtin ("locals" ), [], [])
852
+ locs = ast . Call (self .builtin ("locals" ), [], [])
860
853
inlocs = ast .Compare (ast .Str (name .id ), [ast .In ()], [locs ])
861
854
dorepr = self .helper ("_should_repr_global_name" , name )
862
855
test = ast .BoolOp (ast .Or (), [inlocs , dorepr ])
@@ -883,7 +876,7 @@ def visit_BoolOp(self, boolop):
883
876
res , expl = self .visit (v )
884
877
body .append (ast .Assign ([ast .Name (res_var , ast .Store ())], res ))
885
878
expl_format = self .pop_format_context (ast .Str (expl ))
886
- call = ast_Call (app , [expl_format ], [])
879
+ call = ast . Call (app , [expl_format ], [])
887
880
self .on_failure .append (ast .Expr (call ))
888
881
if i < levels :
889
882
cond = res
@@ -912,9 +905,9 @@ def visit_BinOp(self, binop):
912
905
res = self .assign (ast .BinOp (left_expr , binop .op , right_expr ))
913
906
return res , explanation
914
907
915
- def visit_Call_35 (self , call ):
908
+ def visit_Call (self , call ):
916
909
"""
917
- visit `ast.Call` nodes on Python3.5 and after
910
+ visit `ast.Call` nodes
918
911
"""
919
912
if isinstance (call .func , ast .Name ) and call .func .id == "all" :
920
913
return self ._visit_all (call )
@@ -968,46 +961,6 @@ def visit_Starred(self, starred):
968
961
new_starred = ast .Starred (res , starred .ctx )
969
962
return new_starred , "*" + expl
970
963
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
-
1011
964
def visit_Attribute (self , attr ):
1012
965
if not isinstance (attr .ctx , ast .Load ):
1013
966
return self .generic_visit (attr )
0 commit comments