[Python-checkins] cpython (3.4): add matrix multiplication operator support to 2to3
benjamin.peterson
python-checkins at python.org
Thu Apr 10 06:15:42 CEST 2014
http://hg.python.org/cpython/rev/63dee6d79fd5
changeset: 90207:63dee6d79fd5
branch: 3.4
parent: 90203:a3299de5fc93
user: Benjamin Peterson <benjamin at python.org>
date: Thu Apr 10 00:12:47 2014 -0400
summary:
add matrix multiplication operator support to 2to3
files:
Lib/lib2to3/Grammar.txt | 4 ++--
Lib/lib2to3/pgen2/grammar.py | 1 +
Lib/lib2to3/pgen2/token.py | 13 +++++++------
Lib/lib2to3/pgen2/tokenize.py | 2 +-
Lib/lib2to3/tests/test_parser.py | 6 ++++++
Misc/NEWS | 2 ++
6 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/Lib/lib2to3/Grammar.txt b/Lib/lib2to3/Grammar.txt
--- a/Lib/lib2to3/Grammar.txt
+++ b/Lib/lib2to3/Grammar.txt
@@ -56,7 +56,7 @@
expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
-augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
+augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
# For normal assignments, additional restrictions enforced by the interpreter
print_stmt: 'print' ( [ test (',' test)* [','] ] |
@@ -119,7 +119,7 @@
and_expr: shift_expr ('&' shift_expr)*
shift_expr: arith_expr (('<<'|'>>') arith_expr)*
arith_expr: term (('+'|'-') term)*
-term: factor (('*'|'/'|'%'|'//') factor)*
+term: factor (('*'|'@'|'/'|'%'|'//') factor)*
factor: ('+'|'-'|'~') factor | power
power: atom trailer* ['**' factor]
atom: ('(' [yield_expr|testlist_gexp] ')' |
diff --git a/Lib/lib2to3/pgen2/grammar.py b/Lib/lib2to3/pgen2/grammar.py
--- a/Lib/lib2to3/pgen2/grammar.py
+++ b/Lib/lib2to3/pgen2/grammar.py
@@ -149,6 +149,7 @@
{ LBRACE
} RBRACE
@ AT
+@= ATEQUAL
== EQEQUAL
!= NOTEQUAL
<> NOTEQUAL
diff --git a/Lib/lib2to3/pgen2/token.py b/Lib/lib2to3/pgen2/token.py
--- a/Lib/lib2to3/pgen2/token.py
+++ b/Lib/lib2to3/pgen2/token.py
@@ -57,12 +57,13 @@
DOUBLESLASH = 48
DOUBLESLASHEQUAL = 49
AT = 50
-OP = 51
-COMMENT = 52
-NL = 53
-RARROW = 54
-ERRORTOKEN = 55
-N_TOKENS = 56
+ATEQUAL = 51
+OP = 52
+COMMENT = 53
+NL = 54
+RARROW = 55
+ERRORTOKEN = 56
+N_TOKENS = 57
NT_OFFSET = 256
#--end constants--
diff --git a/Lib/lib2to3/pgen2/tokenize.py b/Lib/lib2to3/pgen2/tokenize.py
--- a/Lib/lib2to3/pgen2/tokenize.py
+++ b/Lib/lib2to3/pgen2/tokenize.py
@@ -84,7 +84,7 @@
# recognized as two instances of =).
Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"<>", r"!=",
r"//=?", r"->",
- r"[+\-*/%&|^=<>]=?",
+ r"[+\-*/%&@|^=<>]=?",
r"~")
Bracket = '[][(){}]'
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -48,6 +48,12 @@
raise AssertionError("Syntax shouldn't have been valid")
+class TestMatrixMultiplication(GrammarTest):
+ def test_matrix_multiplication_operator(self):
+ self.validate("a @ b")
+ self.validate("a @= b")
+
+
class TestRaiseChanges(GrammarTest):
def test_2x_style_1(self):
self.validate("raise")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -168,6 +168,8 @@
Tools/Demos
-----------
+- Add support for the PEP 465 matrix multiplication operator to 2to3.
+
- Issue #16047: Fix module exception list and __file__ handling in freeze.
Patch by Meador Inge.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list