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

Specialized error messages pegen does not support yet #122

Closed
5 tasks done
lysnikolaou opened this issue Apr 27, 2020 · 7 comments
Closed
5 tasks done

Specialized error messages pegen does not support yet #122

lysnikolaou opened this issue Apr 27, 2020 · 7 comments

Comments

@lysnikolaou
Copy link
Member

lysnikolaou commented Apr 27, 2020

Here is a probably incomplete list of specialized error messages that are not yet supported by pegen and whose tests have been skipped.

  • f(x()=2) throws SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
  • del f() throws SyntaxError: cannot delete function call
  • Assignments to invalid targets, where the invalid target is nested within another valid one. For example (a, "b", c) = (1, 2, 3) throws SyntaxError: cannot assign to literal. This also included cases, where the invalid target is not the first one is a multiple-assignment statement, i.e. a = True = b.
  • Unparenthesized generator expressions as (non-first) function args like f(L, x for x in L), which throws SyntaxError: Generator expression must be parenthesized.
  • def f(*): pass throws SyntaxError: named arguments must follow bare *
@hauntsaninja
Copy link

Here are some examples from mypy test cases where we no longer output specialised error messages:

x, (y, 1) = 1
x, [y, 1] = 1
x, [y, [z, 1]] = 1
x, (y, (z, 1)) = 1
with f() as 1: pass

@lysnikolaou
Copy link
Member Author

Yes, that is also an issue with the current targets situation. There are many errors case in assignment, where we don't output the correct message. Hopefully, #123 will resolve that, if we decide to implement it.

@hauntsaninja
Copy link

Forgot this above, a fairly minor one since you need to parse with type_comments=True for it to happen, but:

def f(
    *, # type: int
    x  # type: str
): ...

throws bare * has associated type comment

@gvanrossum
Copy link

gvanrossum commented May 14, 2020

Oh dear, I tried that, and ast.parse() produces a syntax error that has the entire rest of the file as the text attribute. This gets formatted really weirdly. I just was looking at this code for python#20072, but the problem here is in the ast module and how it interfaces to pegen, not in the formatting of exceptions.

UPDATE: It seems to be happening whenever compile() can't read the source code. (But only for the new parser.) I opened https://bugs.python.org/issue40619

@lysnikolaou
Copy link
Member Author

All the specialised error messages listed here are now supported by the new parser. See among others: python#20076, python#19865, python#20151, python#20153 and python#19911.

@hauntsaninja
Copy link

Maybe there's an unmerged PR I haven't seen, but it looks like the following doesn't have a specialised error message on CPython master: with f() as 1: pass

@pablogsal
Copy link

Maybe there's an unmerged PR I haven't seen, but it looks like the following doesn't have a specialised error message on CPython master: with f() as 1: pass

That should be handled by python#20106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants