-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-129858: Special syntax error for elif block after else
#129902
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
Conversation
Previously, having an elif block after an else block would raise a standard syntax error.
|
@pablogsal I see that you've been tagged for review. Please see the associated issue for discussion about whether an even more sophisticated error message is possible. |
Please add a test. There should be tests in some |
|
@picnixz No problem--will do. |
|
I've implemented a test as requested, though I'll hold off on committing or pushing it until we decide on the exact wording of the error message. |
|
Those last two commits should appear as being from this GitHub account. Let me see if I can delete them and try again. |
|
In general, we avoid force-pushing, but you can do it in this case and amend the commit author and put the correct email address. (Not sure if it could help in this though) |
62996a0 to
883ada9
Compare
|
The force push seems to have fixed the problem without any issues. The usernames for my work and personal email differ by one letter, which is occasionally inconvenient. |
|
|
We can draw inspiration from here, I suppose? |
|
What about this? I'm not sure if the blocks need something more realistic than
>>> if word.startswith('a'):
... pass
... else:
... pass
... elif word.startswith('b'):
... pass
File "<stdin>", line 5
elif word.startswith('b'):
^^^^
SyntaxError: 'elif' block follows an 'else' block |
Yes that's what I had in mind. |
|
Another possibility is: >>> if who == "me":
... print("This is me!")
... else:
... print("This is not me!")
... elif who is None:
... print("Who is it?")
File "<stdin>", line 5
elif who is None:
^^^^
SyntaxError: 'elif' block follows an 'else' block |
|
I like that, but I think I'll do "It's me!" and "It's not me!" in honor of Elphaba, |
Let's go for this one :) |
|
We also get a subtle homage to Britney :) |
Misc/NEWS.d/next/Core_and_Builtins/2025-02-12-01-36-13.gh-issue-129858.M-f7Gb.rst
Outdated
Show resolved
Hide resolved
hugovk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR from main which will fix the unrelated "computed changes" error.
Misc/NEWS.d/next/Core_and_Builtins/2025-02-12-01-36-13.gh-issue-129858.M-f7Gb.rst
Outdated
Show resolved
Hide resolved
…e-129858.M-f7Gb.rst Co-authored-by: Hugo van Kemenade <[email protected]>
Previously, having an elif block after an else block would raise a standard syntax error. This PR implements a special syntax error saying "elif not allowed after else".
I compiled cpython with this version of the parser and confirmed that it doesn't conflict with other special syntax or indentation errors.
elifafterelse#129858