From 1ea1881226851477460cb436dee51d4b515015ca 2014-11-22 20:17:30 From: Pascal Bugnion Date: 2014-11-22 20:17:30 Subject: [PATCH] Fixed whitespace bug when pasting IPython continuation prompt. Fixes a SyntaxError that arose when pasting code containing the IPython continuation prompt without a trailing white space, such as: In[1]: if True: ...: print "No space after ':' on next line." ...: This might arise if the user only copies up to the end of the last prompt, without copying the trailing whitespace. This commit adds a regression test and fixes the regular expression that strips continuation prompts, making the whitespace optional. --- diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py index 2c379dd..daf40b0 100644 --- a/IPython/core/inputtransformer.py +++ b/IPython/core/inputtransformer.py @@ -461,7 +461,7 @@ def classic_prompt(): def ipy_prompt(): """Strip IPython's In [1]:/...: prompts.""" # FIXME: non-capturing version (?:...) usable? - prompt_re = re.compile(r'^(In \[\d+\]: |\s*\.{3,}: )') + prompt_re = re.compile(r'^(In \[\d+\]: |\s*\.{3,}: ?)') return _strip_prompts(prompt_re) diff --git a/IPython/core/tests/test_inputtransformer.py b/IPython/core/tests/test_inputtransformer.py index bb5b576..4f11e22 100644 --- a/IPython/core/tests/test_inputtransformer.py +++ b/IPython/core/tests/test_inputtransformer.py @@ -233,6 +233,11 @@ syntax_ml = \ ('...: print i',' print i'), ('...: ', ''), ], + [('In [24]: for i in range(10):','for i in range(10):'), + # Space after last continuation prompt has been removed (issue #6674) + ('...: print i',' print i'), + ('...:', ''), + ], [('In [2]: a="""','a="""'), (' ...: 123"""','123"""'), ],