-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Syntax errors in else
blocks are reported at else
#119724
Comments
else
blocks are ignoredelse
blocks are reported at else
@lysnikolaou Do you think this can be solved soon? Beta 2 is coming up; if this can't be fixed quickly it might be better to revert #29513 and try again. Marking as a potential release blocker. |
I gave this a go yesterday, but I couldn't come up with something that both fixes this and keeps the current behavior when there's an unmatched |
…ching 'elif'/'else' statements (python#29513)" This reverts commit 1c8f912.
Would you consider this an improvement? Python 3.14.0a0 (heads/autoconf/curses-dirty:739af749138, Jun 3 2024, 13:59:59) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> if 1:
... pass
... else:
... This is invalid syntax (sic)
File "<unknown>", line 4
This is invalid syntax (sic)
^
SyntaxError: 'else' must match a valid statement here
>>> |
Hard to say with that example. Here is a less minimal one; IMO the error should be “near” the bad line: if 1:
pass
else:
while True:
do_necessary_things()
if should_end:
retrun True # sic
do_correct_things()
do_good_things() |
In this case, yes it shows the offending line, but not the exact column. |
Yeah, I think the correct thing to do here is reverting |
I couldn't make it work well. Let's revert and reevaluate. |
yeah, the ratio benefit/complexity it's quite important for these error messages and I prefer to have something dummer than showing incorrect things to the user or having to maintain some gigantic rule so it's fine to just not do it |
…non-matching 'elif'/'else' statements (pythonGH-29513)" (pythonGH-119974) This reverts commit 1c8f912. (cherry picked from commit 31a4fb3) Co-authored-by: Petr Viktorin <encukou@gmail.com>
…non-matching 'elif'/'else' statements (pythonGH-29513)" (pythonGH-119974) This reverts commit 1c8f912. (cherry picked from commit 31a4fb3) Co-authored-by: Petr Viktorin <encukou@gmail.com>
…ching 'elif'/'else' statements (python#29513)" (python#119974) This reverts commit 1c8f912.
…ching 'elif'/'else' statements (python#29513)" (python#119974) This reverts commit 1c8f912.
…ching 'elif'/'else' statements (python#29513)" (python#119974) This reverts commit 1c8f912.
Since #29513, syntax errors in
else
andelif
blocks, like:are reported at the
else
:This is quite unhelpful when a small typo is hiding in a large block.
@lysnikolaou, could you take a look?
Linked PRs
The text was updated successfully, but these errors were encountered: