Skip to content

Paste from clipboard on REPL may lose the input #6017

@moreal

Description

@moreal

Since it is about REPL mode, it may not be so important.

Summary

There is an issue where source code from the clipboard doesn't paste properly into the REPL shell. I tested this by copying and pasting the string below. Please refer to the content in the attached Actual section below.

# From https://github.com/RustPython/RustPython/issues/5715#issuecomment-3035167400
# Copy only following lines.
print("Hello, RustPython!")

a = 10
b = 20
result = a + b
print(f"10 + 20 = {result}")

name = "RustPython"
print(f"Welcome to {name}")

numbers = [1, 2, 3, 4, 5]
print(f"Numbers: {numbers}")
print(f"Sum: {sum(numbers)}")

Personally, I wasn't able to easily identify the cause of this issue. It appears that the behavior differs depending on the terminal. When pasting in VSCode, it seems like everything gets entered (although it may be truncated), but when pasting in Ghostty, nothing after the arbtrary line gets entered.

I suspect this problem occurs because rustyline doesn't handle stdin buffer management or similar processing.

Expected

Maybe, there is no expectation for REPL implementation but I leave CPython's case.

>>> print("Hello, RustPython!")
...
... a = 10
... b = 20
... result = a + b
... print(f"10 + 20 = {result}")
...
... name = "RustPython"
... print(f"Welcome to {name}")
...
... numbers = [1, 2, 3, 4, 5]
... print(f"Numbers: {numbers}")
... print(f"Sum: {sum(numbers)}")
...
Hello, RustPython!
10 + 20 = 30
Welcome to RustPython
Numbers: [1, 2, 3, 4, 5]
Sum: 15
>>>

Actual

VSCode + RustPython

Welcome to the magnificent Rust Python 0.4.0 interpreter 😱 🖖
RustPython 3.13.0
Type "help", "copyright", "credits" or "license" for more information.
>>>>> print("Hello, RustPython!")
Hello, RustPython!
>>>>> = a + b
  File "<stdin>", line 1
    = a + b
    ^
SyntaxError: expected a statement
>>>>> Python"
  File "<stdin>", line 1
    Python"
          ^
SyntaxError: missing closing quote in string literal
>>>>>  2, 3, 4, 5]
  File "<stdin>", line 1
    2, 3, 4, 5]
IndentationError: unexpected indentation
>>>>> Sum: {sum(numbers)}")
  File "<stdin>", line 1
    Sum: {sum(numbers)}")
                       ^
SyntaxError: missing closing quote in string literal
>>>>>

Ghostty + RustPython

Welcome to the magnificent Rust Python 0.4.0 interpreter 😱 🖖
RustPython 3.13.0
Type "help", "copyright", "credits" or "license" for more information.
>>>>> print("Hello, RustPython!")
f"10 + 20 = {result}")

name = "RustPython"
print(f"Welcome to {name}")

numbers = [1, 2, 3, 4, 5]
print(f"Numbers: {numbers}")
print(f"Sum: {sum(numbers)}")Hello, RustPython!
>>>>> f"10 + 20 = {result}")
  File "<stdin>", line 1
    f"10 + 20 = {result}")
                         ^
SyntaxError: expected a statement
>>>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions