Skip to content

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

Closed
@treyhunner

Description

@treyhunner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions