PyREPL: Send code using bracketed paste markers - #26178
Merged
Merged
Conversation
Eduardo Villalpando Mello (edvilme)
requested a review
from Anthony Kim (anthonykim1)
October 1, 2026 00:20
|
|
||
| // For new _pyrepl for Python3.13+ && !shellIntegration, we need to send code via bracketed paste mode. | ||
| if (object.attach_bracket_paste && !shellIntegrationEnabled && _replType === ReplType.terminal) { | ||
| // For the new _pyrepl in Python 3.13+, send code via bracketed paste mode so the REPL |
There was a problem hiding this comment.
I don't recall exact detail, but the indentation logic has been funky and probably worth revisiting with newer models. Maybe there were some nuances with PY_REPL flag + shell integration combination.
Also recommend these 4 scenarios when it comes to manually testing and ensuring coverage for run selection of Python code (via shift+enter, or UI):
When I say shell integration, I mean both the terminal.integrated.shellIntegration.enabled and python.terminal.shellIntegration.enabled
>=Python3.13 with shell integration enabled.<Python 3.13 with shell integration enabled.>=Python3.13 with shell integration disabled.<Python 3.13 with shell integration disabled.
Anthony Kim (anthonykim1)
previously approved these changes
Oct 1, 2026
Eduardo Villalpando Mello (edvilme)
force-pushed
the
pyrepl-bracketed-paste
branch
from
October 1, 2026 22:36
bf2cba8 to
bb63145
Compare
Eduardo Villalpando Mello (edvilme)
enabled auto-merge (squash)
October 1, 2026 22:37
Rich Chiodo (rchiodo)
approved these changes
Oct 1, 2026
Eduardo Villalpando Mello (edvilme)
requested a review
from Anthony Kim (anthonykim1)
October 2, 2026 00:10
Bill Schnurr (bschnurr)
approved these changes
Oct 2, 2026
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.




Fixes #26176.
Problem
On Python 3.13+, using Shift+Enter to run selected/multiline code in the integrated terminal progressively increased the indentation of continuation lines, eventually raising
IndentationError: unexpected indent(regression observed in2026.6.0).Root cause
The new Python 3.13 PyREPL auto-indents interactively typed input. Terminal REPL code is delivered via
terminal.sendText(...)and nevershellIntegration.executeCommand(...)(the Python path inTerminalService.executeCommandreturns early), so bracketed paste markers are the only thing that tells the PyREPL "this is pasted text — preserve its whitespace".CodeExecutionHelper.normalizeLinesonly attached those markers when shell integration was disabled:But the PyREPL stays active even when shell integration is enabled — shell integration is provided from inside Python via
PYTHONSTARTUP/pythonrc.py, which makes the REPL's ownPS1emit OSC 633 sequences (the pink/violet>>>users noticed). So with shell integration on (the default), the markers were skipped, raw multiline code was typed into the auto-indenting REPL, and indentation grew line by line.Fix
Attach bracketed paste for Python 3.13+ terminal sends regardless of the
terminal.shellIntegration.enabledsetting, since terminal REPL input always goes throughsendText:The now-unused
shellIntegrationEnabledlookup was removed.Changes
src/client/terminals/codeExecution/helper.ts— drop the!shellIntegrationEnabledguard so bracketed paste is applied for the 3.13+ PyREPL in the terminal whether or not shell integration is enabled; remove the unused setting read.src/test/terminals/codeExecution/helper.test.ts— replace the obsolete "BASIC_REPL does not attach bracketed paste" test (which only passed because readingsettings.terminal.shellIntegrationthrew and hit the catch) with a Shift+Enter progressively changes indentation when running Python code in the terminal #26176 regression test asserting that multiline, indented code sent to a 3.13+ terminal REPL is wrapped in bracketed paste, with indentation preserved verbatim, even when shell integration is enabled.Note
This supersedes the earlier approach of wrapping inside
TerminalServicedirectly, which double-wrapped PyREPL users (the helper already wraps) and risked sending bracketed-paste markers to non-PyREPL interpreters. Thoseservice.ts/service.unit.test.tschanges are reverted.