mirror of
https://github.com/python/cpython
synced 2024-10-14 17:56:08 +00:00
gh-118908: Fix completions after namespace change in REPL (#120370)
This commit is contained in:
parent
19435d299a
commit
02e74c3562
|
@ -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
|
||||
|
||||
|
|
|
@ -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>"
|
||||
|
|
Loading…
Reference in a new issue