From 561ff1fa710493dee8c6482f990bd17535b27040 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Tue, 21 May 2024 16:30:45 -0400 Subject: [PATCH 1/2] gh-111201: Remove readline dependency from the PyREPL (#119262) --- Lib/_pyrepl/readline.py | 4 ++-- Lib/test/test_pyrepl/__init__.py | 1 - .../Library/2024-05-20-20-30-57.gh-issue-111201.DAA5lC.rst | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-05-20-20-30-57.gh-issue-111201.DAA5lC.rst diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py index 0adecf235a4eb4..9c85ce175fd6d6 100644 --- a/Lib/_pyrepl/readline.py +++ b/Lib/_pyrepl/readline.py @@ -31,9 +31,9 @@ from dataclasses import dataclass, field import os -import readline from site import gethistoryfile # type: ignore[attr-defined] import sys +from rlcompleter import Completer as RLCompleter from . import commands, historical_reader from .completing_reader import CompletingReader @@ -84,7 +84,7 @@ @dataclass class ReadlineConfig: - readline_completer: Completer | None = readline.get_completer() + readline_completer: Completer | None = RLCompleter().complete completer_delims: frozenset[str] = frozenset(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?") diff --git a/Lib/test/test_pyrepl/__init__.py b/Lib/test/test_pyrepl/__init__.py index a9bc41f4d39f60..fa38b86b847dd9 100644 --- a/Lib/test/test_pyrepl/__init__.py +++ b/Lib/test/test_pyrepl/__init__.py @@ -7,7 +7,6 @@ # option. Additionally, we need to attempt to import curses and readline. requires("curses") curses = import_module("curses") -readline = import_module("readline") def load_tests(*args): diff --git a/Misc/NEWS.d/next/Library/2024-05-20-20-30-57.gh-issue-111201.DAA5lC.rst b/Misc/NEWS.d/next/Library/2024-05-20-20-30-57.gh-issue-111201.DAA5lC.rst new file mode 100644 index 00000000000000..15cd79dec378ee --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-20-20-30-57.gh-issue-111201.DAA5lC.rst @@ -0,0 +1 @@ +Remove dependency to :mod:`readline` from the new Python REPL. From de8f530841b55885b919677a6938ab33d4a92f20 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 21 May 2024 22:33:52 +0200 Subject: [PATCH 2/2] gh-119102: Fix REPL for dumb terminal (#119332) The site module gets the __main__ module to get _pyrepl.__main__. --- Lib/site.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/site.py b/Lib/site.py index 4ba078388a37b8..f1a6d9cf66fdc3 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -523,7 +523,12 @@ def register_readline(): pass def write_history(): - from _pyrepl.__main__ import CAN_USE_PYREPL + try: + # _pyrepl.__main__ is executed as the __main__ module + from __main__ import CAN_USE_PYREPL + except ImportError: + CAN_USE_PYREPL = False + try: if os.getenv("PYTHON_BASIC_REPL") or not CAN_USE_PYREPL: readline.write_history_file(history)