python / python/cpython

Associativity of matmul unclear from grammar for m_expr

Open
#117,961 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs easy
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Documentation

6.7. Binary arithmetic operations shows the grammar rule

m_expr ::=  u_expr | m_expr "*" u_expr | m_expr "@" m_expr |
            m_expr "//" u_expr | m_expr "/" u_expr |
            m_expr "%" u_expr

in which all operators except @ for matmul are left-associative (meaning, a*b*c parses as m_expr a*b and u_expr c ) while @ is ambiguous: Does a@b@c parse as m_expr a@b and m_expr c or as m_expr a and m_expr b@c?

According to PEP 465, @ should have the same associativity as *. Should this grammar rule should reflect that by saying m_expr "@" u_expr, that is, with the right-hand side changed from m_expr to u_expr?

Linked PRs
  • gh-138847
  • gh-145636
  • gh-149281

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the 6.7 Binary arithmetic operations section linked in the issue and compare its m_expr grammar with the associativity specified in PEP 465. Review linked PRs gh-138847, gh-145636, and gh-149281; done means the documentation makes @ associativity unambiguous and matches the specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.