[pypy-commit] pyrepl default: [PyPy issue1221] raw_input() should return a string instead of unicode.

amauryfa noreply at buildbot.pypy.org
Sat Jul 21 12:40:55 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r198:e123d5cc94ce
Date: 2012-07-21 12:40 +0200
http://bitbucket.org/pypy/pyrepl/changeset/e123d5cc94ce/

Log:	[PyPy issue1221] raw_input() should return a string instead of
	unicode. Actually a typo in the readline() call... Test and fix.

diff --git a/pyrepl/readline.py b/pyrepl/readline.py
--- a/pyrepl/readline.py
+++ b/pyrepl/readline.py
@@ -181,7 +181,7 @@
 
     def __init__(self):
         self.f_in = os.dup(0)
-        self.f_ut = os.dup(1)
+        self.f_out = os.dup(1)
 
     def get_reader(self):
         if self.reader is None:
@@ -196,7 +196,7 @@
         except _error:
             return _old_raw_input(prompt)
         reader.ps1 = prompt
-        return reader.readline(reader, startup_hook=self.startup_hook)
+        return reader.readline(startup_hook=self.startup_hook)
 
     def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
         """Read an input on possibly multiple lines, asking for more
diff --git a/testing/test_readline.py b/testing/test_readline.py
new file mode 100644
--- /dev/null
+++ b/testing/test_readline.py
@@ -0,0 +1,13 @@
+from pyrepl.readline import _ReadlineWrapper
+import os, pty
+
+def test_raw_input():
+    readline_wrapper = _ReadlineWrapper()
+    master, slave = pty.openpty()
+    readline_wrapper.f_in = slave
+    os.write(master, 'input\n')
+    result = readline_wrapper.raw_input('prompt:')
+    assert result == 'input'
+    # A bytes string on python2, a unicode string on python3.
+    assert isinstance(result, str)
+


More information about the pypy-commit mailing list