From a2148b56ea6000444eec9628493e4aa3e9534c47 Mon Sep 17 00:00:00 2001 From: bretello Date: Sun, 29 Oct 2023 17:48:43 +0100 Subject: [PATCH] readline: get rid of raw_input code in _setup --- pyrepl/readline.py | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/pyrepl/readline.py b/pyrepl/readline.py index 23ba864..b3b6235 100644 --- a/pyrepl/readline.py +++ b/pyrepl/readline.py @@ -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 @@ -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()