gh-127960 Fix the REPL to set the correct namespace by setting the correct __main__ module (gh-134275)

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.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2025-05-21 19:18:00 -05:00 committed by GitHub
parent a66bae8bb5
commit b1b8962443
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 85 additions and 34 deletions

View file

@ -17,8 +17,8 @@ if TYPE_CHECKING:
def make_default_module_completer() -> ModuleCompleter:
# Inside pyrepl, __package__ is set to '_pyrepl'
return ModuleCompleter(namespace={'__package__': '_pyrepl'})
# Inside pyrepl, __package__ is set to None by default
return ModuleCompleter(namespace={'__package__': None})
class ModuleCompleter: