-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Flag starred expressions in return
and yield
#16520
Comments
Python's Python 3.11.4 (main, Sep 30 2023, 10:54:38) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.parse('def f(): return *x')
<ast.Module object at 0x7d5c2433d0> which indicates to me that this syntax error is detected by CPython's compiler rather than CPython's parser. That means that this issue is a sub-issue of #11934. It doesn't mean that we shouldn't detect the syntax error (we absolutely should!). But it does mean that we may want a way of suppressing the diagnostic internally so that we can continue to test our parser directly against CPython's parser using e.g. the |
Thanks @AlexWaygood That would suggest that this should be implemented as a semantic syntax error, outside the parser. |
I'll start moving some of the other errors from #6591 to #11934 too. I think the Python 3.12.9 (main, Feb 12 2025, 14:50:50) [Clang 19.1.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.parse("""
... a=5
...
... def f():
... try:
... pass
... except:
... global a
... else:
... print(a)
... """)
<ast.Module object at 0x79c0c0e06d10> |
Good call. Some of the existing errors listed in #11934 and its sub-issues may also have been introduced in recent versions of CPython; we'll need to check when implementing those semantic syntax errors whether they should be emitted for all target versions or not |
(I think from Python 3.9, you can test the CPython parser directly using |
Both of these are invalid on every Python version I've tried and should be flagged as
ParseError
s in the parser:They result in
SyntaxError: can't use starred expression here
on 3.8 and 3.13 and the less helpfulSyntaxError: invalid syntax
on 3.7.This is separate from the related case in #16485 where these are part of a tuple, which is allowed after 3.8.
Originally posted by @ntBre in #16485 (comment)
The text was updated successfully, but these errors were encountered: