Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: correctly identify error location on soft-keywords #2648

Closed
isidentical opened this issue Nov 26, 2021 · 2 comments · Fixed by #2649
Closed

parser: correctly identify error location on soft-keywords #2648

isidentical opened this issue Nov 26, 2021 · 2 comments · Fixed by #2649
Labels
T: enhancement New feature or request

Comments

@isidentical
Copy link
Collaborator

Currently it only throws the error on the first-seen node (?):

(.venv) (3.9.5) [  6:53ÖS ]  [ isidentical@msi:~ ]
 $ cat t.py                                                                                                   140ms
def something():
    match something:
        case t:
            pass

    match arg:
        case t:
            print(t)
        case z := u:
            print(a)
(.venv) (3.9.5) [  6:53ÖS ]  [ isidentical@msi:~ ]
 $ black -tpy310 --fast t.py                                                                                    2ms
error: cannot format t.py: Cannot parse: 2:10:     match something:
Oh no! 💥 💔 💥
1 file failed to reformat.
(.venv) (3.9.5) [  6:53ÖS ]  [ isidentical@msi:~ ]
 $ .venv310/bin/python -m ast t.py                                                                            147ms
Traceback (most recent call last):
 File "t.py", line 9
    case z := u:
           ^^
SyntaxError: expected ':'
@isidentical isidentical added the T: enhancement New feature or request label Nov 26, 2021
@JelleZijlstra
Copy link
Collaborator

This is because it tries multiple grammars in parsing.py. I added some print statements:

(black) jelle@mbpt-root black % black -t py310 t.py
try <blib2to3.pgen2.grammar.Grammar object at 0x103180d30>
Cannot parse: 9:15:         case z := u:
try <blib2to3.pgen2.grammar.Grammar object at 0x103180cd0>
Cannot parse: 2:10:     match something:
error: cannot format t.py: Cannot parse: 2:10:     match something:

I think it shouldn't try other grammars if we're in -t py310 mode.

@isidentical
Copy link
Collaborator Author

Ah nice catch @JelleZijlstra, I thought it was a bug on the parser.

JelleZijlstra added a commit that referenced this issue Dec 1, 2021
Fixes #2648.

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants