Skip to content

gh-85560: Fix IDLE paren matching with "else" or "yield" at the start of a continuation line - #157693

Merged
terryjreedy merged 3 commits into
python:mainfrom
serhiy-storchaka:gh-85560-else-synchre
Sep 22, 2026
Merged

terryjreedy merged 3 commits into
python:mainfrom
serhiy-storchaka:gh-85560-else-synchre

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

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.

🤖 Generated with Claude Code

… 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.
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Sep 17, 2026
… 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.
@serhiy-storchaka serhiy-storchaka changed the title gh-85560: Fix IDLE paren matching with "else" at the start of a continuation line gh-85560: Fix IDLE paren matching with "else" or "yield" at the start of a continuation line Sep 17, 2026
"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.
@terryjreedy

Copy link
Copy Markdown
Member

Fix looks good. Started reviewing test.

@terryjreedy
terryjreedy merged commit 2073473 into python:main Sep 22, 2026
51 checks passed
@miss-islington-app

Copy link
Copy Markdown

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.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Sep 22, 2026

Copy link
Copy Markdown

GH-157959 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 22, 2026
@bedevere-app

bedevere-app Bot commented Sep 22, 2026

Copy link
Copy Markdown

GH-157960 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 22, 2026
@bedevere-app

bedevere-app Bot commented Sep 22, 2026

Copy link
Copy Markdown

GH-157961 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 22, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants