mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
[3.13] gh-118908: Fix completions after namespace change in REPL (GH-120370) (#120392)
(cherry picked from commit 02e74c3562
)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
parent
8f5ce42f34
commit
10821ccf06
2 changed files with 12 additions and 5 deletions
|
@ -55,6 +55,11 @@ Command = commands.Command
|
||||||
from collections.abc import Callable, Collection
|
from collections.abc import Callable, Collection
|
||||||
from .types import Callback, Completer, KeySpec, CommandName
|
from .types import Callback, Completer, KeySpec, CommandName
|
||||||
|
|
||||||
|
TYPE_CHECKING = False
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
MoreLinesCallable = Callable[[str], bool]
|
MoreLinesCallable = Callable[[str], bool]
|
||||||
|
|
||||||
|
@ -92,7 +97,7 @@ __all__ = [
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ReadlineConfig:
|
class ReadlineConfig:
|
||||||
readline_completer: Completer | None = RLCompleter().complete
|
readline_completer: Completer | None = None
|
||||||
completer_delims: frozenset[str] = frozenset(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?")
|
completer_delims: frozenset[str] = frozenset(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?")
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,7 +559,7 @@ for _name, _ret in [
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
def _setup() -> None:
|
def _setup(namespace: dict[str, Any]) -> None:
|
||||||
global raw_input
|
global raw_input
|
||||||
if raw_input is not None:
|
if raw_input is not None:
|
||||||
return # don't run _setup twice
|
return # don't run _setup twice
|
||||||
|
@ -570,9 +575,11 @@ def _setup() -> None:
|
||||||
_wrapper.f_in = f_in
|
_wrapper.f_in = f_in
|
||||||
_wrapper.f_out = f_out
|
_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
|
# this is not really what readline.c does. Better than nothing I guess
|
||||||
import builtins
|
import builtins
|
||||||
|
|
||||||
raw_input = builtins.input
|
raw_input = builtins.input
|
||||||
builtins.input = _wrapper.input
|
builtins.input = _wrapper.input
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,9 @@ def run_multiline_interactive_console(
|
||||||
console: code.InteractiveConsole | None = None,
|
console: code.InteractiveConsole | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
from .readline import _setup
|
from .readline import _setup
|
||||||
_setup()
|
|
||||||
|
|
||||||
namespace = mainmodule.__dict__ if mainmodule else DEFAULT_NAMESPACE
|
namespace = mainmodule.__dict__ if mainmodule else DEFAULT_NAMESPACE
|
||||||
|
_setup(namespace)
|
||||||
|
|
||||||
if console is None:
|
if console is None:
|
||||||
console = InteractiveColoredConsole(
|
console = InteractiveColoredConsole(
|
||||||
namespace, filename="<stdin>"
|
namespace, filename="<stdin>"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue