@@ -413,9 +413,9 @@ def _check_if_assertion_pass_impl():
413413 return True if util ._assertion_pass else False
414414
415415
416- unary_map = {ast .Not : "not %s" , ast .Invert : "~%s" , ast .USub : "-%s" , ast .UAdd : "+%s" }
416+ UNARY_MAP = {ast .Not : "not %s" , ast .Invert : "~%s" , ast .USub : "-%s" , ast .UAdd : "+%s" }
417417
418- binop_map = {
418+ BINOP_MAP = {
419419 ast .BitOr : "|" ,
420420 ast .BitXor : "^" ,
421421 ast .BitAnd : "&" ,
@@ -438,20 +438,8 @@ def _check_if_assertion_pass_impl():
438438 ast .IsNot : "is not" ,
439439 ast .In : "in" ,
440440 ast .NotIn : "not in" ,
441+ ast .MatMult : "@" ,
441442}
442- # Python 3.5+ compatibility
443- try :
444- binop_map [ast .MatMult ] = "@"
445- except AttributeError :
446- pass
447-
448- # Python 3.4+ compatibility
449- if hasattr (ast , "NameConstant" ):
450- _NameConstant = ast .NameConstant
451- else :
452-
453- def _NameConstant (c ):
454- return ast .Name (str (c ), ast .Load ())
455443
456444
457445def set_location (node , lineno , col_offset ):
@@ -774,7 +762,7 @@ def visit_Assert(self, assert_):
774762 variables = [
775763 ast .Name (name , ast .Store ()) for name in self .format_variables
776764 ]
777- clear_format = ast .Assign (variables , _NameConstant (None ))
765+ clear_format = ast .Assign (variables , ast . NameConstant (None ))
778766 self .statements .append (clear_format )
779767
780768 else : # Original assertion rewriting
@@ -800,7 +788,7 @@ def visit_Assert(self, assert_):
800788 # Clear temporary variables by setting them to None.
801789 if self .variables :
802790 variables = [ast .Name (name , ast .Store ()) for name in self .variables ]
803- clear = ast .Assign (variables , _NameConstant (None ))
791+ clear = ast .Assign (variables , ast . NameConstant (None ))
804792 self .statements .append (clear )
805793 # Fix line numbers.
806794 for stmt in self .statements :
@@ -880,13 +868,13 @@ def visit_BoolOp(self, boolop):
880868 return ast .Name (res_var , ast .Load ()), self .explanation_param (expl )
881869
882870 def visit_UnaryOp (self , unary ):
883- pattern = unary_map [unary .op .__class__ ]
871+ pattern = UNARY_MAP [unary .op .__class__ ]
884872 operand_res , operand_expl = self .visit (unary .operand )
885873 res = self .assign (ast .UnaryOp (unary .op , operand_res ))
886874 return res , pattern % (operand_expl ,)
887875
888876 def visit_BinOp (self , binop ):
889- symbol = binop_map [binop .op .__class__ ]
877+ symbol = BINOP_MAP [binop .op .__class__ ]
890878 left_expr , left_expl = self .visit (binop .left )
891879 right_expr , right_expl = self .visit (binop .right )
892880 explanation = "({} {} {})" .format (left_expl , symbol , right_expl )
@@ -953,7 +941,7 @@ def visit_Compare(self, comp):
953941 if isinstance (next_operand , (ast .Compare , ast .BoolOp )):
954942 next_expl = "({})" .format (next_expl )
955943 results .append (next_res )
956- sym = binop_map [op .__class__ ]
944+ sym = BINOP_MAP [op .__class__ ]
957945 syms .append (ast .Str (sym ))
958946 expl = "{} {} {}" .format (left_expl , sym , next_expl )
959947 expls .append (ast .Str (expl ))
0 commit comments