8000 gh-118908: Use __main__ for the default PyREPL namespace by ambv · Pull Request #121054 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

ambv
Copy link
Contributor
@ambv ambv commented Jun 26, 2024

This allows for PYTHONSTARTUP to execute in the same namespace that the interpreter later operates in.

Looks like Eugene was right in his initial implementation of the fix. We can't create a synthetic namespace because then Modules/main.c:pymain_run_startup is running in a namespace that isn't used later. There's probably more edge cases that using a synthetic namespace created; in Python __main__ is clearly expected as the namespace for interaction.

Since -i exposes a different module as __main__, I see no reason why regular REPL execution shouldn't expose __file__ pointing at _pyrepl.__main__. Therefore, I adapted the test.