Pythonrc: Don't pollute PyREPL with variables - #26148
Merged
Merged
Conversation
Eduardo Villalpando Mello (edvilme)
marked this pull request as draft
September 10, 2026 17:49
Eduardo Villalpando Mello (edvilme)
force-pushed
the
pyrepl-pythonrc-leak
branch
from
September 10, 2026 17:53
fee0e45 to
6d682f9
Compare
Eduardo Villalpando Mello (edvilme)
marked this pull request as ready for review
September 10, 2026 17:57
Eduardo Villalpando Mello (edvilme)
requested a balanced review from Copilot
September 10, 2026 17:57
Copilot started reviewing on behalf of
Eduardo Villalpando Mello (edvilme)
September 10, 2026 17:58
View session
There was a problem hiding this comment.
🟢 Approval recommended
The focused refactor preserves behavior, adds appropriate regression coverage, and has no identified issues.
Pull request overview
Refactors Python REPL startup initialization to prevent internal variables leaking into the interactive namespace.
Changes:
- Encapsulates setup logic in a temporary initializer.
- Updates integration tests and adds namespace-cleanliness coverage.
File summaries
| File | Description |
|---|---|
python_files/pythonrc.py |
Isolates and removes initialization symbols. |
python_files/tests/test_shell_integration.py |
Tests installed hooks and namespace cleanliness. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
Bill Schnurr (bschnurr)
approved these changes
Sep 10, 2026
Bill Schnurr (bschnurr)
left a comment
Member
There was a problem hiding this comment.
Approved via Review Center.
Rich Chiodo (rchiodo)
approved these changes
Sep 10, 2026
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Eduardo Villalpando Mello (edvilme)
enabled auto-merge (squash)
September 10, 2026 22:34
Eduardo Villalpando Mello (edvilme)
merged commit Sep 10, 2026
cb7b164
into
main
96 of 97 checks passed
Eduardo Villalpando Mello (edvilme)
deleted the
pyrepl-pythonrc-leak
branch
September 10, 2026 22:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #26147
Before
After
This pull request refactors the initialization logic in
python_files/pythonrc.pyto avoid polluting the module's global namespace, and adds a corresponding test to ensure this behavior. The main change is wrapping the script's setup code in a private function and then deleting it after execution.Refactoring and namespace cleanliness:
pythonrc.pyinto a private_initialize()function, and called and deleted it at the end of the file to prevent leftover names in the module's global namespace. [1] [2]Testing:
test_does_not_pollute_namespaceintest_shell_integration.pyto verify thatpythonrc.pydoes not leave any non-dunder (non-__) names in its global namespace after import.