[pypy-commit] pypy default: The logic to ask the user for more lines was confused by the
arigo
noreply at buildbot.pypy.org
Tue Apr 14 10:02:26 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r76787:57faf10f021d
Date: 2015-04-14 10:02 +0200
http://bitbucket.org/pypy/pypy/changeset/57faf10f021d/
Log: The logic to ask the user for more lines was confused by the
automatically-inserted indentation, and would ask for one extra line
since b37ef838fa61.
diff --git a/lib_pypy/pyrepl/simple_interact.py b/lib_pypy/pyrepl/simple_interact.py
--- a/lib_pypy/pyrepl/simple_interact.py
+++ b/lib_pypy/pyrepl/simple_interact.py
@@ -33,6 +33,16 @@
return False
return True
+def _strip_final_indent(text):
+ # kill spaces and tabs at the end, but only if they follow '\n'.
+ # meant to remove the auto-indentation only (although it would of
+ # course also remove explicitly-added indentation).
+ short = text.rstrip(' \t')
+ n = len(short)
+ if n > 0 and text[n-1] == '\n':
+ return short
+ return text
+
def run_multiline_interactive_console(mainmodule=None):
import code
if mainmodule is None:
@@ -41,7 +51,7 @@
def more_lines(unicodetext):
# ooh, look at the hack:
- src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
+ src = "#coding:utf-8\n"+_strip_final_indent(unicodetext).encode('utf-8')
try:
code = console.compile(src, '<stdin>', 'single')
except (OverflowError, SyntaxError, ValueError):
@@ -58,7 +68,7 @@
returns_unicode=True)
except EOFError:
break
- more = console.push(statement)
+ more = console.push(_strip_final_indent(statement))
assert not more
except KeyboardInterrupt:
console.write("\nKeyboardInterrupt\n")
More information about the pypy-commit
mailing list