simplify + fix

This commit is contained in:
Matthias Bussonnier 2015-06-24 21:53:52 +02:00 committed by Thomas Kluyver
parent 3bc6c0f936
commit 167625d24d
2 changed files with 17 additions and 15 deletions

View File

@ -238,18 +238,24 @@ class DebugInterpreter(ast.NodeVisitor):
arg_explanations.append(arg_explanation)
for keyword in call.keywords:
arg_explanation, arg_result = self.visit(keyword.value)
if keyword.arg:
arg_name = "__exprinfo_%s" % (len(ns),)
ns[arg_name] = arg_result
keyword_source = "%s=%%s" % (keyword.arg)
arguments.append(keyword_source % (arg_name,))
arg_explanations.append(keyword_source % (arg_explanation,))
if sys.version_info <= (3,4) and call.starargs:
else: # starargs in 3.5+
arg_name = "__exprinfo_star"
ns[arg_name] = arg_result
arguments.append("*%s" % (arg_name,))
arg_explanations.append("*%s" % (arg_explanation,))
if getattr(call, 'starargs', None): # no starargs in 3.5
arg_explanation, arg_result = self.visit(call.starargs)
arg_name = "__exprinfo_star"
ns[arg_name] = arg_result
arguments.append("*%s" % (arg_name,))
arg_explanations.append("*%s" % (arg_explanation,))
if sys.version_info <= (3,4) and call.kwargs:
if call.kwargs:
arg_explanation, arg_result = self.visit(call.kwargs)
arg_name = "__exprinfo_kwds"
ns[arg_name] = arg_result

View File

@ -774,22 +774,18 @@ class AssertionRewriter(ast.NodeVisitor):
new_args = []
new_kwargs = []
for arg in call.args:
if type(arg) is ast.Starred:
new_star, expl = self.visit(arg)
arg_expls.append("*" + expl)
new_args.append(new_star)
else:
res, expl = self.visit(arg)
new_args.append(res)
if type(arg) is ast.Starred:
arg_expls.append("*" + expl)
else:
arg_expls.append(expl)
new_args.append(res)
for keyword in call.keywords:
if keyword.arg:
res, expl = self.visit(keyword.value)
new_kwargs.append(ast.keyword(keyword.arg, res))
if keyword.arg:
arg_expls.append(keyword.arg + "=" + expl)
else: ## **args have `arg` keywords with an .arg of None
res, expl = self.visit(keyword.value)
new_kwargs.append(ast.keyword(keyword.arg, res))
arg_expls.append("**" + expl)
expl = "%s(%s)" % (func_expl, ', '.join(arg_expls))