Skip to content

Commit 8222889

Browse files
committed
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.
1 parent 27bd082 commit 8222889

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/_pyrepl/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import errno
22
import os
33
import sys
4+
import types
45

56

67
CAN_USE_PYREPL: bool
@@ -32,9 +33,8 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
3233
if mainmodule:
3334
namespace = mainmodule.__dict__
3435
else:
35-
import __main__
36+
__main__ = types.ModuleType("__main__")
3637
namespace = __main__.__dict__
37-
namespace.pop("__pyrepl_interactive_console", None)
3838

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

0 commit comments

Comments
 (0)