Skip to content
Next Next commit
Make _pyrepl not to use the __main__ module as the namespace
The `__main__` module imported in the `_pyrepl` module points to the `_pyrepl` module itself when the interpreter was launched without `-m` option and didn't execute a module,
while it's an unexpected behavior that `__main__` can be `_pyrepl` and relative imports such as `from . import *` works based on the `_pyrepl` module.
  • Loading branch information
whitphx committed May 19, 2025
commit 8222889f71a6904806074d93d9d78cb1b55a5826
4 changes: 2 additions & 2 deletions Lib/_pyrepl/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import errno
import os
import sys
import types


CAN_USE_PYREPL: bool
Expand Down Expand Up @@ -32,9 +33,8 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
if mainmodule:
namespace = mainmodule.__dict__
else:
import __main__
__main__ = types.ModuleType("__main__")
namespace = __main__.__dict__
namespace.pop("__pyrepl_interactive_console", None)

# sys._baserepl() above does this internally, we do it here
startup_path = os.getenv("PYTHONSTARTUP")
Expand Down