gh-118908: Use __main__ for the default PyREPL namespace (#121054)

This commit is contained in:
Łukasz Langa 2024-06-26 15:01:10 -04:00 committed by GitHub
parent e51e880e75
commit d611c4c8e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 75 additions and 67 deletions

View file

@ -80,23 +80,13 @@ REPL_COMMANDS = {
"clear": _clear_screen,
}
DEFAULT_NAMESPACE: dict[str, Any] = {
'__name__': '__main__',
'__doc__': None,
'__package__': None,
'__loader__': None,
'__spec__': None,
'__annotations__': {},
'__builtins__': builtins,
}
def run_multiline_interactive_console(
mainmodule: ModuleType | None = None,
namespace: dict[str, Any],
future_flags: int = 0,
console: code.InteractiveConsole | None = None,
) -> None:
from .readline import _setup
namespace = mainmodule.__dict__ if mainmodule else DEFAULT_NAMESPACE
_setup(namespace)
if console is None: