Skip to content

Fix Python >= 3.13 terminal execution requiring manual Enter keypresses #25157

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 10, 2025

Problem

In Python >= 3.13, when using "Run selection/line" to execute multi-line code blocks in the terminal, users had to manually press Enter to complete execution. This was causing the REPL to show continuation prompts ("...") instead of executing the code automatically.

For example, executing this code:

def hello():
    print("Hello, World!")

Would result in:

>>> def hello():
...     print("Hello, World!")
... 

Requiring manual Enter keypresses to execute, instead of running automatically.

Root Cause

The issue was in the bracket paste mode logic for Python >= 3.13:

  1. normalizeSelection.py correctly adds trailing newlines (\n\n) for multi-line code blocks to ensure proper execution
  2. The bracket paste mode handling in helper.ts was removing these essential trailing newlines
  3. Without sufficient trailing newlines, Python 3.13's new REPL behavior shows continuation prompts instead of executing

Solution

  • Preserved trailing newlines: Removed the logic that trimmed trailing newlines for Python >= 3.13 bracket paste mode
  • Maintained existing behavior: Simple expressions still work correctly with appropriate newlines
  • Added test coverage: New test ensures multi-line code blocks preserve necessary trailing newlines

The fix is minimal and surgical - it simply preserves the correct normalization that normalizeSelection.py already provides:

  • Simple expressions: 1 trailing newline (sufficient for execution)
  • Multi-line blocks: 2 trailing newlines (required for Python 3.13 execution)

Testing

  • ✅ All existing tests pass
  • ✅ New test specifically validates the fix for multiline code blocks
  • ✅ No regression in existing functionality
  • ✅ Python < 3.13 behavior unchanged

Fixes #24565.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Python >= 3.13 Attempt to execute all the commands sent, without requiring manual 'Enter' keypress Fix Python >= 3.13 terminal execution requiring manual Enter keypresses Jun 10, 2025
@Copilot Copilot AI requested a review from anthonykim1 June 10, 2025 04:21
Copilot finished work on behalf of anthonykim1 June 10, 2025 04:21
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.

Python >= 3.13 Attempt to execute all the commands sent, without requiring manual 'Enter' keypress
2 participants