Fix #1290: Py3.5's @ operator/assertion rewriting.

This commit is contained in:
TomV 2016-02-05 22:30:07 +00:00
parent b5dc7d9be1
commit 7d107018e8
3 changed files with 21 additions and 0 deletions

View File

@ -1,6 +1,9 @@
2.8.8.dev1 2.8.8.dev1
---------- ----------
- fix #1290: support Python 3.5's @ operator in assertion rewriting.
Thanks Shinkenjoe for report with test case and Tom Viner for the PR.
2.8.7 2.8.7
----- -----

View File

@ -453,6 +453,11 @@ binop_map = {
ast.In: "in", ast.In: "in",
ast.NotIn: "not in" ast.NotIn: "not in"
} }
# Python 3.5+ compatibility
try:
binop_map[ast.MatMult] = "@"
except AttributeError:
pass
# Python 3.4+ compatibility # Python 3.4+ compatibility
if hasattr(ast, "NameConstant"): if hasattr(ast, "NameConstant"):

View File

@ -279,6 +279,19 @@ class TestAssertionRewrite:
assert False or 4 % 2 assert False or 4 % 2
assert getmsg(f) == "assert (False or (4 % 2))" assert getmsg(f) == "assert (False or (4 % 2))"
@pytest.mark.skipif("sys.version_info < (3,5)")
def test_at_operator_issue1290(self, testdir):
testdir.makepyfile("""
class Matrix:
def __init__(self, num):
self.num = num
def __matmul__(self, other):
return self.num * other.num
def test_multmat_operator():
assert Matrix(2) @ Matrix(3) == 6""")
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