Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-118908: Fix completions after namespace change in REPL #120370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions 13 Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?")


Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions 4 Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.