You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sharing media and context from merged PR #26148 for verification:
Before
After
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.
Activity
vs-code-engineering commentedon Sep 10, 2026
Sharing media and context from merged PR #26148 for verification:
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.Source PR: #26148
Pythonrc: Don't pollute PyREPL with variables (microsoft#26148)
sysandplatformmodules into namespace when running PYTHONSTARTUP in integrated terminal #25904 as a duplicate of this issue