cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Copy-pasted multi-statement block cannot be extended with new REPL

Open treyhunner opened this issue 1 year ago • 1 comments

Bug report

Bug description:

To reproduce, copy paste this into the Python REPL:

from dataclasses import dataclass

@dataclass
class Point:
    x: float
    y: float

You'll see:

>>> from dataclasses import dataclass
...
... @dataclass
... class Point:
...     x: float
...     y: float
...
>>>

Now attempt to edit that class to include z: float (in addition to x: float and y: float).

To do this, hit the up arrow key to edit the previous block and you'll see:

>>> from dataclasses import dataclass
...
... @dataclass
... class Point:
...     x: float
...     y: float

Hitting Enter will then execute the block of code (notice that there's no blank line at the end):

>>> from dataclasses import dataclass
...
... @dataclass
... class Point:
...     x: float
...     y: float
>>>

If from dataclasses import dataclass is not included in the pasted text, adding z: float is possible (as expected). Given that, I suspect this is a special case related to there being multiple distinct top-level blocks/statements within the pasted text.

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-121757

treyhunner avatar Jul 11 '24 01:07 treyhunner

looks like it's because of this https://github.com/python/cpython/blob/main/Lib/_pyrepl/simple_interact.py#L124

saucoide avatar Jul 13 '24 15:07 saucoide

Thanks for the fix, @saucoide! ✨ 🍰 ✨

ambv avatar Jul 16 '24 09:07 ambv