Rewrite unrolled assertion with a new rewriter,correctly append the unrolled for loop
This commit is contained in:
parent
765f75a8f1
commit
470e686a70
|
@ -994,16 +994,21 @@ warn_explicit(
|
||||||
if not isinstance(call.args[0], ast.GeneratorExp):
|
if not isinstance(call.args[0], ast.GeneratorExp):
|
||||||
return
|
return
|
||||||
gen_exp = call.args[0]
|
gen_exp = call.args[0]
|
||||||
|
assertion_module = ast.Module(
|
||||||
|
body=[ast.Assert(test=gen_exp.elt, lineno=1, msg="", col_offset=1)]
|
||||||
|
)
|
||||||
|
AssertionRewriter(None, None).run(assertion_module)
|
||||||
for_loop = ast.For(
|
for_loop = ast.For(
|
||||||
iter=gen_exp.generators[0].iter,
|
iter=gen_exp.generators[0].iter,
|
||||||
target=gen_exp.generators[0].target,
|
target=gen_exp.generators[0].target,
|
||||||
body=[
|
body=assertion_module.body,
|
||||||
self.visit(ast.Assert(test=gen_exp.elt, lineno=1, msg="", col_offset=1))
|
orelse=[],
|
||||||
],
|
|
||||||
)
|
)
|
||||||
ast.fix_missing_locations(for_loop)
|
self.statements.append(for_loop)
|
||||||
for_loop = ast.copy_location(for_loop, call)
|
return (
|
||||||
return for_loop, ""
|
ast.Num(n=1),
|
||||||
|
"",
|
||||||
|
) # Return an empty expression, all the asserts are in the for_loop
|
||||||
|
|
||||||
def visit_Starred(self, starred):
|
def visit_Starred(self, starred):
|
||||||
# From Python 3.5, a Starred node can appear in a function call
|
# From Python 3.5, a Starred node can appear in a function call
|
||||||
|
|
Loading…
Reference in New Issue