Skip to content

Commit c2f81b1

Browse files
committed
[PyPy issue1221] raw_input() should return a string instead of unicode.
Actually a typo in the readline() call... Test and fix.
1 parent 4bbc903 commit c2f81b1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pyrepl/readline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class _ReadlineWrapper(object):
181181

182182
def __init__(self):
183183
self.f_in = os.dup(0)
184-
self.f_ut = os.dup(1)
184+
self.f_out = os.dup(1)
185185

186186
def get_reader(self):
187187
if self.reader is None:
@@ -196,7 +196,7 @@ def raw_input(self, prompt=''):
196196
except _error:
197197
return _old_raw_input(prompt)
198198
reader.ps1 = prompt
199-
return reader.readline(reader, startup_hook=self.startup_hook)
199+
return reader.readline(startup_hook=self.startup_hook)
200200

201201
def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
202202
"""Read an input on possibly multiple lines, asking for more

testing/test_readline.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pyrepl.readline import _ReadlineWrapper
2+
import os, pty
3+
4+
def test_raw_input():
5+
readline_wrapper = _ReadlineWrapper()
6+
master, slave = pty.openpty()
7+
readline_wrapper.f_in = slave
8+
os.write(master, 'input\n')
9+
result = readline_wrapper.raw_input('prompt:')
10+
assert result == 'input'
11+
# A bytes string on python2, a unicode string on python3.
12+
assert isinstance(result, str)
13+

0 commit comments

Comments
 (0)