Repository navigation
gh-157612: Strip prompts and output from pasted REPL sessions - #157615
johnslavik wants to merge 5 commits into
Conversation
Documentation build overview
129 files changed ·
|
There was a problem hiding this comment.
I think it should also consider cases in which the prompts have been changed. I think these would be few but still ?
E.g., (not endorsing changing the prompt, but something that could happen, especially in other tools modifying the REPL)
>>> import sys
>>> sys.ps1 = "py> "
py> # This is code I want to copy and paste later
py> class A(object):
... def __new__(self):
... raise TypeError("i do not exist")
...
py> class B(A):
... __new__ = object.__new__
... def __init__(self, x):
... self.x = x
...
py> B(1)|
We could, but I find that limiting this to Do you personally customize your PS1 and would need that in this feature? |
|
Not explicitly but it is documented behavior on the tutorial. |
Would a user paste something that contains ANSI sequences?
What tools or IDEs modify Footnotes
|
|
Please also note that |
|
Oh you are right, didn't consider the case for it not being a string :) |
Copy a REPL example from a web page and paste it straight into the new REPL:
At an empty
>>>prompt, the REPL removes the copied prompts and output, leaving this code ready to edit:Indentation stays intact. Nothing runs on paste, so you can change
double(3)todouble(5)before running it.This also makes it easier to send students examples or copy code between two REPLs to compare different parameters. You no longer need to delete prompts and output by hand.
The terminal must support bracketed paste, which tells the REPL where a paste starts and ends. The input must be empty, and the paste must start with a standard
>>>prompt. Pasting into existing code, a string, or aninput()prompt keeps the text unchanged.Rough edges
As discussed in the issue, this only recognizes
>>>and..., since those are the prompts most web examples use. Output that looks like a prompted code line will also be kept as code.The pasted code runs as one block, so it can behave differently from entering each command separately. The issue notes differences involving
sys.displayhookandbuiltins._.Tests cover prompt and output removal, different line endings, pastes that should stay unchanged, and editing before running.
>>>and...when pasting to REPL #157612