https://github.com/python/cpython/commit/10821ccf0671a5d660ab5df7b5d4bfa0e9c8d112
commit: 10821ccf0671a5d660ab5df7b5d4bfa0e9c8d112
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: lysnikolaou <[email protected]>
date: 2024-06-12T08:48:22Z
summary:

[3.13] gh-118908: Fix completions after namespace change in REPL (GH-120370) 
(#120392)

(cherry picked from commit 02e74c356223feb0771759286d24d1dbac01d4ca)

Co-authored-by: Lysandros Nikolaou <[email protected]>

files:
M Lib/_pyrepl/readline.py
M Lib/_pyrepl/simple_interact.py

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index b10d0c66e4f813..28f592d80b1b03 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -55,6 +55,11 @@
 from collections.abc import Callable, Collection
 from .types import Callback, Completer, KeySpec, CommandName
 
+TYPE_CHECKING = False
+
+if TYPE_CHECKING:
+    from typing import Any
+
 
 MoreLinesCallable = Callable[[str], bool]
 
@@ -92,7 +97,7 @@
 
 @dataclass
 class ReadlineConfig:
-    readline_completer: Completer | None = RLCompleter().complete
+    readline_completer: Completer | None = None
     completer_delims: frozenset[str] = frozenset(" 
\t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?")
 
 
@@ -554,7 +559,7 @@ def stub(*args: object, **kwds: object) -> None:
 # ____________________________________________________________
 
 
-def _setup() -> None:
+def _setup(namespace: dict[str, Any]) -> None:
     global raw_input
     if raw_input is not None:
         return  # don't run _setup twice
@@ -570,9 +575,11 @@ def _setup() -> None:
     _wrapper.f_in = f_in
     _wrapper.f_out = f_out
 
+    # set up namespace in rlcompleter
+    _wrapper.config.readline_completer = RLCompleter(namespace).complete
+
     # this is not really what readline.c does.  Better than nothing I guess
     import builtins
-
     raw_input = builtins.input
     builtins.input = _wrapper.input
 
diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index 620f87b4867073..2de3b38c37a9da 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -96,9 +96,9 @@ def run_multiline_interactive_console(
     console: code.InteractiveConsole | None = None,
 ) -> None:
     from .readline import _setup
-    _setup()
-
     namespace = mainmodule.__dict__ if mainmodule else DEFAULT_NAMESPACE
+    _setup(namespace)
+
     if console is None:
         console = InteractiveColoredConsole(
             namespace, filename="<stdin>"

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to