Skip to content

Commit cb9f8ba

Browse files
committed
Patch from pypy's 0d7e8867e6c0
1 parent b1a9a3d commit cb9f8ba

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pyrepl/readline.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,21 @@ def _setup():
395395
_wrapper.f_in = f_in
396396
_wrapper.f_out = f_out
397397

398-
if hasattr(sys, '__raw_input__'): # PyPy
399-
_old_raw_input = sys.__raw_input__
398+
if '__pypy__' in sys.builtin_module_names: # PyPy
399+
400+
def _old_raw_input(prompt=''):
401+
# sys.__raw_input__() is only called when stdin and stdout are
402+
# as expected and are ttys. If it is the case, then get_reader()
403+
# should not really fail in _wrapper.raw_input(). If it still
404+
# does, then we will just cancel the redirection and call again
405+
# the built-in raw_input().
406+
try:
407+
del sys.__raw_input__
408+
except AttributeError:
409+
pass
410+
return raw_input(prompt)
400411
sys.__raw_input__ = _wrapper.raw_input
412+
401413
else:
402414
# this is not really what readline.c does. Better than nothing I guess
403415
import __builtin__

0 commit comments

Comments
 (0)