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
Minor improvement to errors with (no) missing colon #92858
Comments
cc @pablogsal |
Yeah, go ahead! Thanks for looking into this :) Take care because the reason this may not be already made is because there may be some hairy incompatibility down the line (I cannot remember any so it is likely that I just forgot) so make sure to run the test suite :) |
Note that the error is much friendlier with Python 3.11's (edit: meant 3.10) better tracebacks, since the carets point the location of the error, so you can't confuse it for another colon on the line:
which I think I prefer compared to the error in the proposed PR:
|
I read In cases other than that I don't think the fact that the parser expected a colon adds much information over a plain syntax error (and may be slightly confusing). |
Unless I am missing something very fundamental, there is nothing in 3.11 for this, this should work also on Python 3.10 as I added the changes required for range highlighting in syntax errors early in the 3.10 dev cycle.
Technically means "the parser expected a colon here" which can be compatible with a colon being late in the line. Is not technically a suggestion but more than an explanation on what's goin on.
Sorry, not sure I follow. What cases are you referring to? The example that you showed? In general, missing colon errors have been one of the most requested specialized error messages so I think it does make sense to have them appear instead of "invalid syntax" as much as possible. Regarding this case that you show: the problem is that currently we have some suites working like you show and others not working like that (the ones using the mode that you are using in your PR). In general, I prefer to be consistent if we can, because that simplifies expectations, which is an important (although not fundamenteal) part of the UX here. |
Sorry, I misspoke there (remove 'in cases'). I was trying to say that I think the missing colon error isn't really helpful when the solution isn't to add/move a colon. In the case mentioned, It also seemed to be a similar case for pretty much all cases that my PR changes (see added test cases on the PR). The only exception I could think of is where there is a colon missing and the body is on the same line, e.g. There are cases such as
Agreed. I felt changing the |
Yeah, I think is going to be better to do follow what while loops are doing. The errors that way are less surprising I will review your PR soon. Thanks a lot for working on this :) |
…tax error before ':' (pythonGH-92894) (cherry picked from commit 2fc83ac) Co-authored-by: wookie184 <wookie1840@gmail.com>
…tax error before ':' (pythonGH-92894). (cherry picked from commit 2fc83ac) Co-authored-by: wookie184 <wookie1840@gmail.com>
Some invalid
for
statements currently give the specific errorexpected ':'
even if there is a colon on the line. I think it would be a slight improvement to raise a more general error in these cases. This is howwhile
andif
already behave.Current behaviour:
Proposed behaviour:
Proposed Implementation:
Would do it the same way
while
andif
do it. For the for loop example it would be something like this:I'd also apply this to other suites where it makes sense (e.g.
with
,match/case
, andtry
)Would it be OK for me to submit a PR making these changes? (this is my first time looking into the CPython parser so apologies if I made any obvious mistakes!)
The text was updated successfully, but these errors were encountered: