Python 3.5+astterm
ast.MatMult
operators
The marker for the binary operator @ in an ast tree: it sits in BinOp.op and AugAssign.op and has no fields.
Syntax
ast.MatMult()
The @ operator (matrix multiplication, PEP 465) is not supported by built-in types — numpy and the like implement it via __matmul__. The same @ before def is a decorator: it lands in FunctionDef.decorator_list and creates no MatMult. 'a @= b' is an AugAssign with MatMult.
Examples
import ast
print(type(ast.parse('a @ b', mode='eval').body.op).__name__) # → MatMult
fn = ast.parse('@cache\ndef f(): pass').body[0]
print(fn.decorator_list[0].id) # → cache
See also
Open in the full glossarydocs.python.orgReport an inaccuracy