gh-85560: Fix IDLE paren matching with "else" or "yield" at the start of a continuation line - #157693
Merged
Merged
Conversation
… continuation line pyparse took a line starting with "else" for the start of a statement, so the parenthesis containing a conditional expression continued on such a line was not found. Now "else" is a statement start only if it is followed by a colon.
… start of a continuation line pyparse took a line starting with "else" or "yield" for the start of a statement, so the parenthesis containing a conditional expression or a yield expression continued on such a line was not found. Now "else" is a statement start only if it is followed by a colon, and "yield" is not a statement start.
"with", "del", "global", "nonlocal", "pass" and "finally" cannot start a continuation line, so they are safe synchronization points, and let find_good_parse_start() cut the parsed text closer to its end.
Member
|
Fix looks good. Started reviewing test. |
|
Thanks @serhiy-storchaka for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-157959 is a backport of this pull request to the 3.15 branch. |
|
GH-157960 is a backport of this pull request to the 3.14 branch. |
|
GH-157961 is a backport of this pull request to the 3.13 branch. |
terryjreedy
pushed a commit
that referenced
this pull request
Sep 22, 2026
…e start of a continuation line (GH-157693) (#157960) gh-85560: Fix IDLE paren matching with "else" or "yield" at the start of a continuation line (GH-157693) `pyparse._synchre` took any line starting with `else` or `yield` for the start of a statement, so the parenthesis containing a conditional expression or a yield expression continued on such a line (`(1 if x\n else 0)`, `(\n yield x)`) was not found by Show Surrounding Parens. An `else` statement is always followed by a colon, a conditional expression never, so `else` now counts as a statement start only when followed by `:`. A `yield` statement cannot be told from a yield expression, so `yield` is removed from the list; it only served to shorten the parsed text. On the other hand, `with`, `del`, `global`, `nonlocal`, `pass` and `finally`, which cannot start a continuation line, are added. (cherry picked from commit 2073473) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
terryjreedy
pushed a commit
that referenced
this pull request
Sep 22, 2026
…e start of a continuation line (GH-157693) (#157961) gh-85560: Fix IDLE paren matching with "else" or "yield" at the start of a continuation line (GH-157693) `pyparse._synchre` took any line starting with `else` or `yield` for the start of a statement, so the parenthesis containing a conditional expression or a yield expression continued on such a line (`(1 if x\n else 0)`, `(\n yield x)`) was not found by Show Surrounding Parens. An `else` statement is always followed by a colon, a conditional expression never, so `else` now counts as a statement start only when followed by `:`. A `yield` statement cannot be told from a yield expression, so `yield` is removed from the list; it only served to shorten the parsed text. On the other hand, `with`, `del`, `global`, `nonlocal`, `pass` and `finally`, which cannot start a continuation line, are added. (cherry picked from commit 2073473) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pyparse._synchretook any line starting withelseoryieldfor the start of a statement, so the parenthesis containing a conditional expression or a yield expression continued on such a line ((1 if x\n else 0),(\n yield x)) was not found by Show Surrounding Parens. Anelsestatement is always followed by a colon, a conditional expression never, soelsenow counts as a statement start only when followed by:. Ayieldstatement cannot be told from a yield expression, soyieldis removed from the list; it only served to shorten the parsed text. On the other hand,with,del,global,nonlocal,passandfinally, which cannot start a continuation line, are added.🤖 Generated with Claude Code