Skip to content
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

Pasting a function definition does not work in 3.13 REPL with Windows Terminal #124096

Open
japageth opened this issue Sep 15, 2024 · 7 comments
Open
Labels
OS-windows topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@japageth
Copy link

japageth commented Sep 15, 2024

Bug report

Bug description:

I use Python downloaded from python.org without using a graphical environment such as IPython. Instead, I use the Windows Terminal with the REPL built into python.exe. In 3.12.6, I can paste a function definition copied from a text editor directly into the REPL and everything works fine. In 3.13.rc2 this does not work; the indentation is all messed up and I get an IndentationError.

def letter_colors(word, guess):
    '''Compute letter colors for Wordle guesses.  B=black Y=yellow G=green'''
    if (n := len(word)) != len(guess):
        raise ValueError('Word and guess must be the same length.')
    result = ['G' if wl == gl else 'B' for (wl, gl) in zip(word, guess)]
    unused = [w for (w, r) in zip(word, result) if r == 'B']
    for i, c in enumerate(guess):
        if result[i] != 'G' and c in unused:
            result[i] = 'Y'
            unused.remove(c)
    return ''.join(result)

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Windows

Linked PRs

@japageth japageth added the type-bug An unexpected behavior, bug, or error label Sep 15, 2024
@Eclips4 Eclips4 added OS-windows topic-repl Related to the interactive shell labels Sep 15, 2024
@terryjreedy
Copy link
Member

The code you show looks fine to me. Is this what you see in 3.13?
Please copy and paste the full traceback or message.

@Wulian233
Copy link
Contributor

The bug can be reproduced, here is a screenshot

2024-09-15 192801

Duplicate #122237
PR #122383

@terryjreedy
Copy link
Member

Thank you for the additional clear info. Closing as duplicate.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2024
@y5c4l3
Copy link
Contributor

y5c4l3 commented Sep 16, 2024

Duplicate #122237 PR #122383

This is not a duplicate. It's a Windows-specific issue that WinAPI requires a console application to set their input handle with ENABLE_VIRTUAL_TERMINAL_INPUT flag before it can be talked in VT escaped sequences. The flag isn't set in windows_console.py, so it's impossible to have bracketed-paste wrapping sequences sent to PYREPL.

Even if it is set, the default Windows command prompt, at least on 21H2 LTSC, does not support bracketed-paste. A modern terminal emulator like your Windows Terminal is required for this feature. We need to figure out a way to make an educated guess at user's terminal and turn off the autoindentation if necessary.

PYREPL is atm only scanning virtual key codes under Windows, once the console is configured as a virtual terminal, all the keys will be sent in VT sequences.

PR: #124119

After fix

@Wulian233
Copy link
Contributor

oh, you are right
@terryjreedy We need reopen this

@MMateo1120
Copy link

MMateo1120 commented Nov 16, 2024

I am using VS Code on Windows, and extra indentations are added when I shift+enter my code to run in the terminal. Also, even if I just copy the code into the terminal extra indentations are added. Any solution to the problem so far? The problem seems similar to microsoft/vscode-python#24256 where it was solved for some by the pre-lease version of python extension for vs code, but still exist for me on Windows.

Uninstalled every extension but python's:
386728750-ad8e3b32-eb8e-42ff-86a5-b1f3de710e2a

I am using the pre-lease version:
386728870-d9e2007b-583e-4c42-b279-e0b39afd29bb

the python version of 3.13.0 64-bit:
386729104-28dad9bf-286c-4f35-8165-c86d1540439d

Started a new window, a brand new py file but after shift+enter, the same behaviour is found as before:
386729493-971b11ae-adb4-4c7d-9986-8099a425fafc

If i ctrl c ctrl v the code into the terminal, extra indents are added just by the copying of the code into the terminal:
386729985-9389dc83-1bf1-43d5-b986-c3dea30d811d

@anthonykim1
Copy link

Adding to @MMateo1120 folks are also able to repro this outside of VS Code terminal (in external terminal) where indentations breaks like the image above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

7 participants