Skip to content

Pasting into new REPL doesn't end continuations on blank line, interferes with "follow-along" examples #133972

@ferdnyc

Description

@ferdnyc

Bug report

Bug description:

This is somewhat related to #131217, although I don't know if the associated PR would affect it.

When pasting into the new REPL, the pasted text is treated as one long input. That seems like a good thing, but it interferes with pasting text that's supposed to show output between the statements. Many such texts are found in our own documentation, as examples. For example (no pun):

The Format examples section of the string-formatting docs contains this example block:

>>> '{0}, {1}, {2}'.format('a', 'b', 'c')
'a, b, c'
>>> '{}, {}, {}'.format('a', 'b', 'c')  # 3.1+ only
'a, b, c'
>>> '{2}, {1}, {0}'.format('a', 'b', 'c')
'c, b, a'
>>> '{2}, {1}, {0}'.format(*'abc')      # unpacking argument sequence
'c, b, a'
>>> '{0}{1}{0}'.format('abra', 'cad')   # arguments' indices can be repeated
'abracadabra'

When copied (using the handy new "Copy" button), the copied text will be:

'{0}, {1}, {2}'.format('a', 'b', 'c')

'{}, {}, {}'.format('a', 'b', 'c')  # 3.1+ only

'{2}, {1}, {0}'.format('a', 'b', 'c')

'{2}, {1}, {0}'.format(*'abc')      # unpacking argument sequence

'{0}{1}{0}'.format('abra', 'cad')   # arguments' indices can be repeated

With the old REPL, that could be pasted into an interactive session to "re-create" the example. If I paste into Python 3.11, I get this:

>>> '{0}, {1}, {2}'.format('a', 'b', 'c')
'a, b, c'
>>> 
>>> '{}, {}, {}'.format('a', 'b', 'c')  # 3.1+ only
'a, b, c'
>>> 
>>> '{2}, {1}, {0}'.format('a', 'b', 'c')
'c, b, a'
>>> 
>>> '{2}, {1}, {0}'.format(*'abc')      # unpacking argument sequence
'c, b, a'
>>> 
>>> '{0}{1}{0}'.format('abra', 'cad')   # arguments' indices can be repeated

...I just have to hit Enter one last time to see the output of the last statement pasted.

But with the Python 3.13 REPL, that will paste as this:

>>> '{0}, {1}, {2}'.format('a', 'b', 'c')
... 
... '{}, {}, {}'.format('a', 'b', 'c')  # 3.1+ only
... 
... '{2}, {1}, {0}'.format('a', 'b', 'c')
... 
... '{2}, {1}, {0}'.format(*'abc')      # unpacking argument sequence
... 
... '{0}{1}{0}'.format('abra', 'cad')   # arguments' indices can be repeated
... 

...Hitting Enter gets me only the result of the last statement, but not the others.

The ability to paste texts that include blank lines is very useful in certain situations, don't get me wrong. But at other times it can detract from the utility of the REPL. I don't have a good solution to balancing those concerns.

CPython versions tested on:

3.13, 3.11

Operating systems tested on:

Linux

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