Skip to content

Commit

Permalink
readline: get rid of raw_input code in _setup
Browse files Browse the repository at this point in the history
  • Loading branch information
bretello committed Oct 29, 2023
1 parent 860b435 commit a2148b5
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,8 @@ def stub(*args, **kwds):


def _setup():
# TODO: is the raw_input logic still required?
global _old_raw_input
if _old_raw_input is not None:
global _setup_run
if _setup_run:
return
# don't run _setup twice

Expand All @@ -425,33 +424,6 @@ def _setup():
_wrapper.f_out = f_out
_wrapper.setup_std_streams(sys.stdin, sys.stdout, sys.stderr)

if "__pypy__" in sys.builtin_module_names: # PyPy

def _old_raw_input(prompt=""):
# sys.__raw_input__() is only called when stdin and stdout are
# as expected and are ttys. If it is the case, then get_reader()
# should not really fail in _wrapper.raw_input(). If it still
# does, then we will just cancel the redirection and call again
# the built-in raw_input().
with contextlib.suppress(AttributeError):
del sys.__raw_input__
return input(prompt)

sys.__raw_input__ = _wrapper.raw_input

else:
# this is not really what readline.c does. Better than nothing I guess
try:
import builtins

_old_raw_input = builtins.raw_input
builtins.raw_input = _wrapper.raw_input
except ImportError:
import builtins

_old_raw_input = builtins.input
builtins.input = _wrapper.raw_input


_old_raw_input = None
_setup_run = False
_setup()

0 comments on commit a2148b5

Please sign in to comment.