-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
bpo-45759: Better error messages for non-matching 'elif'/'else' statements #29513
Conversation
Please, next time don't close the old PR as the history of comments and reviews is now lost, which makes more difficult to check things. |
@@ -126,6 +126,7 @@ simple_stmt[stmt_ty] (memo): | |||
| &'nonlocal' nonlocal_stmt | |||
|
|||
compound_stmt[stmt_ty]: | |||
| invalid_compound_stmt |
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.
This is more acceptable, but it will trigger with any compound statement:
with A():
elif 3:
...
SyntaxError: 'elif' must match an if-statement here
Also, a slight minor problem is that at this level we are catching an incorrect keyword in a specific bad context, but there could be lot more. For instance, if you would write:
[x for x in range(3) if 34 elif 12]
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.
Is there anything I should do about those?
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.
No for now, let's discuss first if we are ok with this. We may need to adapt the error message
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.
No for now, let's discuss first if we are ok with this.
I mean, let's wait to see what @lysnikolaou and @isidentical think
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.
Maybe also @cfbolz if he has some time
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.
@pablogsal should we keep waiting for the other reviewers, or should this pull request be closed?
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.
@pablogsal should we keep waiting for the other reviewers, or should this pull request be closed?
We should wait for other reviewers.
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 am currently unable to comment on this issue, so feel free to skip me.
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.
@pablogsal It's been 7 days and I plan on closing this pull request because of inactivity. Should we keep waiting for @lysnikolaou?
I am still not super convinced, but this version of the patch is more concise so it I am more favourable to consider it, although it matches some potentially incorrect cases (although we could fix that with a better error). What do you think @lysnikolaou @isidentical ? |
Fixed a typo I found in |
(I'm commenting as an error-interested bystander) I like this approach! It fits also with what @pablogsal and I discussed on twitter earlier: https://twitter.com/cfbolz/status/1458442881346248708 I wonder whether it would make sense to be quite conservative in adding such rules by making them relatively specific. Eg I think as the patch stands it would also trigger the new error message in code like this:
And it can be argued that it's more likely that the name was misspelled here. So maybe we can make it more specific by changing the rules to:
Or, more strongly, maybe even requiring a Relatedly, I think it makes sense to add some more tests that really explore the boundaries of the new behavior so we get an idea when they apply. Does that make any sense, @pablogsal et al? |
Thanks @cfbolz for the message! In general it makes sense but I would recommend to extend the rule until just the My main worry is precisely the intersection with other errors and the possible false positives and this is what we should carefully examinate to not shoot ourselves in the foot later :) |
Yes, I think to mitigate that we should be quite diligent in collecting varied test cases (this goes a bit beyond the scope of the pull request though) |
@pablogsal Should I extend the rule now? |
Because of inactivity, I'll have to close this commit. |
@thatbirdguythatuknownot, I think closing is premature. Here is an activity graph on pablogsal's profile: The last two weeks he is busy with bug fixes, so this PR just got postponed for a while. Actually, you can even come to his page and click through these squares of the graph to see per day activity, GitHub logs everything. |
@arhadthedev So should I reopen it? |
@thatbirdguythatuknownot Yeah. |
|
Since there is a new pull request and this one has conflicts, can this be closed ? |
It was advised to keep pull requests opened to not lose history of reviews and comments. It can be closed once a decision is made. |
I get a compile error: I notice that this has two conditional expressions: I suggest this is split into two for better readability. |
@MaxwellDupre that isn't part of the PR. |
@MaxwellDupre Thanks for reviving this! @thatbirdguythatuknownot Would you like to continue working on this PR? First step would be to rebase onto current main and fix any conflicts. If you feel you don't have time for this, I can always do the rebase for you as well. Whatever you want. I'm generally in favor of this, so we can continue the discussion after a rebase has been done and we can play around with it some more. |
Sorry, I don't know how to rebase (following the guides I found on the internet; I don't know how to resolve the conflicts). I just started using |
I've pushed a couple of commits to a state where it's mergeable to |
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.
Let's go ahead and merge this!
…ching 'elif'/'else' statements (python#29513)" This reverts commit 1c8f912.
…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.
#89920
https://bugs.python.org/issue45759