-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
REPL requests another line despite syntax error #88367
Comments
This seems a regression from 3.9. >>> foo[x = 1
... ]
File "<stdin>", line 1
foo[x = 1
^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
>>> Note how the syntax error is in line 1 and yet the REPL asks for more input (the "..." prompt) and doesn't stop until I type "]". In 3.9 I just get "SyntaxError: invalid syntax" but the REPL doesn't ask for the second line: >>> foo[x = 1
File "<stdin>", line 1
foo[x = 1
^
SyntaxError: invalid syntax
>>> |
Unfortunately this happens because to generate the error message we check for the equal and the right hand side of the equal (to also discard some false positives) and this triggers the parser to ask for additional tokens. Notice that you don't need to close the ']', just provide an additional token: >>> x = [x=4
... f
File "<stdin>", line 1
x = [x=4
^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='? Unfortunately is not going to be easy to solve without looking at the right hand side :( |
I believe that this is similar to, but not quite as severe as a similar bug in code.interact() https://bugs.python.org/issue43366 which affects IDLE; perhaps fixing this might fix the other issue? |
No, this issue is in the parser while the other is caused by the code module. As I mentioned, this case doesn't ask you for tokens until you close the brace, it just ask you for one extra token because is doing a lookahead. If you give any extra token to satisfy the lookahead: >>> foo[x = 1 $
File "<stdin>", line 1
foo[x = 1 $
^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
>>> It fails immediately even if you didn't close the bracket |
I will try to see if we can do something about this but the only thing I can think of is removing the lookaheads in the invalid comparison rules but then we need to solve the false positives (like keyword arguments) and that's going to be very hard to do without lookaheads |
Could we implement something in the REPL where it refuses to read another |
Yes, I was exactly working in that :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: