Fix assertion rewriting involving Starred + side-effects
This commit is contained in:
parent
4c9cde74ab
commit
690a63b921
|
@ -0,0 +1 @@
|
||||||
|
Fix assertion rewriting involving ``Starred`` + side-effects.
|
|
@ -946,7 +946,8 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
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
|
||||||
res, expl = self.visit(starred.value)
|
res, expl = self.visit(starred.value)
|
||||||
return starred, "*" + expl
|
new_starred = ast.Starred(res, starred.ctx)
|
||||||
|
return new_starred, "*" + expl
|
||||||
|
|
||||||
def visit_Call_legacy(self, call):
|
def visit_Call_legacy(self, call):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -413,6 +413,19 @@ class TestAssertionRewrite(object):
|
||||||
)
|
)
|
||||||
testdir.runpytest().assert_outcomes(passed=1)
|
testdir.runpytest().assert_outcomes(passed=1)
|
||||||
|
|
||||||
|
@pytest.mark.skipif("sys.version_info < (3,5)")
|
||||||
|
def test_starred_with_side_effect(self, testdir):
|
||||||
|
"""See #4412"""
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""\
|
||||||
|
def test():
|
||||||
|
f = lambda x: x
|
||||||
|
x = iter([1, 2, 3])
|
||||||
|
assert 2 * next(x) == f(*[next(x)])
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
testdir.runpytest().assert_outcomes(passed=1)
|
||||||
|
|
||||||
def test_call(self):
|
def test_call(self):
|
||||||
def g(a=42, *args, **kwargs):
|
def g(a=42, *args, **kwargs):
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue