Issue #1194 open

Support Python 3.5's matrix multiplication operator (@)

Antony Lee
created an issue

All's in the title.

Comments (6)

  1. Aaron Meurer

    It seems to lex a@b incorrectly. It still thinks @b is a decorator. It only works if you put the space, a @ b. Since @ is a multiplication-like operator, the space is not always used (and anyway, it's impossible for a@b to be a decorator).

  2. Georg Brandl repo owner

    Well, this is one of the few (maybe the only) instance in Python where a lot more context is required than a lexer can provide.

    Sure, we can add some more heuristics, such as "decorator must start at the beginning of a line", but still:

    x = a \
    @ b
    

    I'll see if I can mitigate the common cases though.

  3. Aaron Meurer

    Is checking if it's on a line before another decorator or function or class definition too context sensitive?

    At any rate, just start of the line would go a long way. I didn't realize PEP 8 recommends breaking before operators. But on the other hand, I think that plus the space rule should be enough. No one puts a space before the @ for a decorator, and conversely,

    x = a\
    @b
    

    seems unbalanced (to me at least).

  4. Georg Brandl repo owner

    Is checking if it's on a line before another decorator or function or class definition too context sensitive?

    Definitely, because that requires potentially infinite lookahead.

    At any rate, just start of the line would go a long way.

    Yep, that's what we should go for.

  5. Log in to comment