[3.13] gh-121790: Fix interactive console initialization (GH-121793) (GH-121822)

(cherry picked from commit e5c7216f37)

Co-authored-by: Milan Oberkirch <milan.oberkirch@geops.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2024-07-16 00:49:41 +02:00 committed by GitHub
parent 0794220a69
commit 5b718e7fc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 85 additions and 42 deletions

View file

@ -58,7 +58,7 @@ from .types import Callback, Completer, KeySpec, CommandName
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any
from typing import Any, Mapping
MoreLinesCallable = Callable[[str], bool]
@ -559,7 +559,7 @@ for _name, _ret in [
# ____________________________________________________________
def _setup(namespace: dict[str, Any]) -> None:
def _setup(namespace: Mapping[str, Any]) -> None:
global raw_input
if raw_input is not None:
return # don't run _setup twice
@ -575,7 +575,9 @@ def _setup(namespace: dict[str, Any]) -> None:
_wrapper.f_in = f_in
_wrapper.f_out = f_out
# set up namespace in rlcompleter
# set up namespace in rlcompleter, which requires it to be a bona fide dict
if not isinstance(namespace, dict):
namespace = dict(namespace)
_wrapper.config.readline_completer = RLCompleter(namespace).complete
# this is not really what readline.c does. Better than nothing I guess