Skip to content

Pythonrc: Don't pollute PyREPL with variables - #26148

Merged
Eduardo Villalpando Mello (edvilme) merged 3 commits into
mainfrom
pyrepl-pythonrc-leak
Sep 10, 2026
Merged

Pythonrc: Don't pollute PyREPL with variables#26148
Eduardo Villalpando Mello (edvilme) merged 3 commits into
mainfrom
pyrepl-pythonrc-leak

Conversation

@edvilme

Copy link
Copy Markdown

Fixes #26147

Before

image

After

image

This pull request refactors the initialization logic in python_files/pythonrc.py to 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:

  • Moved all initialization code in pythonrc.py into 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]
  • Removed unnecessary blank lines and improved code organization for readability. [1] [2] [3]

Testing:

  • Added test_does_not_pollute_namespace in test_shell_integration.py to verify that pythonrc.py does not leave any non-dunder (non-__) names in its global namespace after import.

@edvilme
Eduardo Villalpando Mello (edvilme) marked this pull request as ready for review September 10, 2026 17:57
@edvilme Eduardo Villalpando Mello (edvilme) added the bug Issue identified by VS Code Team member as probable bug label Sep 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@bschnurr

Bill Schnurr (bschnurr) commented Sep 10, 2026

Copy link
Copy Markdown
Member

🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR.

@bschnurr Bill Schnurr (bschnurr) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@bschnurr Bill Schnurr (bschnurr) added the review-auto:approved Automated review: no blocking findings (approval posted). label Sep 10, 2026

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid leaking variables in PyREPL

4 participants