gh-92858: Improve error message for some suites with syntax error before ':' by wookie184 · Pull Request #92894 · python/cpython

Closes #92858

I left suites like try: as they shouldn't have anything before the colon anyway. There wouldn't be something before the colon that could be fixed, so I think the current error is fine.

Here's some before (first) after (second) examples with the test cases in the PR:

    class C(x for x in L):
           ^
SyntaxError: expected ':'
    class C(x for x in L):
              ^^^
SyntaxError: invalid syntax

    class R&D:
           ^
SyntaxError: expected ':'
    class R&D:
           ^
SyntaxError: invalid syntax

    for x in range 10:
                   ^^
SyntaxError: expected ':'
    for x in range 10:
                   ^^
SyntaxError: invalid syntax

    with block ad something:
               ^^
SyntaxError: expected ':'
    with block ad something:
               ^^
SyntaxError: invalid syntax

    match x x:
             ^
SyntaxError: expected ':'
    match x x:
            ^
SyntaxError: invalid syntax