René's URL Explorer Experiment


Title: Avoid loading `sys` and `platform` modules into namespace when running PYTHONSTARTUP in integrated terminal · Issue #25904 · microsoft/vscode-python · GitHub

Open Graph Title: Avoid loading `sys` and `platform` modules into namespace when running PYTHONSTARTUP in integrated terminal · Issue #25904 · microsoft/vscode-python

X Title: Avoid loading `sys` and `platform` modules into namespace when running PYTHONSTARTUP in integrated terminal · Issue #25904 · microsoft/vscode-python

Description: The following way is the recommended method to run PYTHONSTARTUP in a console, the type of which inherits from code.InteractiveConsole: if path := os.getenv('PYTHONSTARTUP'): with tokenize.open(path) as file: sys.audit('cpython.run_start...

Open Graph Description: The following way is the recommended method to run PYTHONSTARTUP in a console, the type of which inherits from code.InteractiveConsole: if path := os.getenv('PYTHONSTARTUP'): with tokenize.open(pat...

X Description: The following way is the recommended method to run PYTHONSTARTUP in a console, the type of which inherits from code.InteractiveConsole: if path := os.getenv('PYTHONSTARTUP'): with tokenize....

Opengraph URL: https://github.com/microsoft/vscode-python/issues/25904

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Avoid loading `sys` and `platform` modules into namespace when running PYTHONSTARTUP in integrated terminal","articleBody":"\u003c!-- ⚠️⚠️ Do Not Delete This! feature_request_template ⚠️⚠️ -->\n\u003c!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->\n\u003c!-- Please search existing issues to avoid creating duplicates. -->\nThe following way is the recommended method to run PYTHONSTARTUP in a console, the type of which inherits from `code.InteractiveConsole`:\n\n```python\nif path := os.getenv('PYTHONSTARTUP'):\n    with tokenize.open(path) as file:\n        sys.audit('cpython.run_startup', path)\n        exec(compile(file.read(), path, 'exec'), console.locals)\n```\n\nbut this loads the `platform` and `sys` modules into the locals dictionary (`readline` on non-windows as well), polluting the namespace and making for a strange user experience (e.g. when one prints the contents of globals during debugging or when forgetting to import modules works anyways)\n\nFrom [`pythonrc.py`](https://github.com/microsoft/vscode-python/blob/main/python_files/pythonrc.py):\n\n```python\nimport platform\nimport sys\n\nif sys.platform != \"win32\":\n    import readline\n\noriginal_ps1 = \">>> \"\nis_wsl = \"microsoft-standard-WSL\" in platform.release()\n\n\nclass REPLHooks:\n    def __init__(self):\n        self.global_exit = None\n        self.failure_flag = False\n        self.original_excepthook = sys.excepthook\n        self.original_displayhook = sys.displayhook\n        sys.excepthook = self.my_excepthook\n        sys.displayhook = self.my_displayhook\n\n    def my_displayhook(self, value):\n        if value is None:\n            self.failure_flag = False\n\n        self.original_displayhook(value)\n\n    def my_excepthook(self, type_, value, traceback):\n        self.global_exit = value\n        self.failure_flag = True\n\n        self.original_excepthook(type_, value, traceback)\n\n\ndef get_last_command():\n    # Get the last history item\n    last_command = \"\"\n    if sys.platform != \"win32\":\n        last_command = readline.get_history_item(readline.get_current_history_length())\n\n    return last_command\n\n\nclass PS1:\n    hooks = REPLHooks()\n    sys.excepthook = hooks.my_excepthook\n    sys.displayhook = hooks.my_displayhook\n\n    # str will get called for every prompt with exit code to show success/failure\n    def __str__(self):\n        exit_code = int(bool(self.hooks.failure_flag))\n        self.hooks.failure_flag = False\n        # Guide following official VS Code doc for shell integration sequence:\n        result = \"\"\n        # For non-windows allow recent_command history.\n        if sys.platform != \"win32\":\n            result = \"{soh}{command_executed}{command_line}{command_finished}{prompt_started}{stx}{prompt}{soh}{command_start}{stx}\".format(\n                soh=\"\\001\",\n                stx=\"\\002\",\n                command_executed=\"\\x1b]633;C\\x07\",\n                command_line=\"\\x1b]633;E;\" + str(get_last_command()) + \"\\x07\",\n                command_finished=\"\\x1b]633;D;\" + str(exit_code) + \"\\x07\",\n                prompt_started=\"\\x1b]633;A\\x07\",\n                prompt=original_ps1,\n                command_start=\"\\x1b]633;B\\x07\",\n            )\n        else:\n            result = \"{command_finished}{prompt_started}{prompt}{command_start}{command_executed}\".format(\n                command_finished=\"\\x1b]633;D;\" + str(exit_code) + \"\\x07\",\n                prompt_started=\"\\x1b]633;A\\x07\",\n                prompt=original_ps1,\n                command_start=\"\\x1b]633;B\\x07\",\n                command_executed=\"\\x1b]633;C\\x07\",\n            )\n\n        # result = f\"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}\"\n\n        return result\n\n    def __repr__(self):\n        return \"\u003cCustom PS1 for VS Code Python Shell Integration>\"\n\n\nif sys.platform != \"win32\" and (not is_wsl):\n    sys.ps1 = PS1()\n\nif sys.platform == \"darwin\":\n    print(\"Cmd click to launch VS Code Native REPL\")\nelse:\n    print(\"Ctrl click to launch VS Code Native REPL\")\n```\n\u003c!-- Describe the feature you'd like. -->\nI propose to add the following at the end of that file:\n\n```python\ndel platform, sys\nif sys.platform != 'win32': del readline\n```","author":{"url":"https://github.com/jonathandung","@type":"Person","name":"jonathandung"},"datePublished":"2026-04-09T12:35:59Z","url":"https://github.com/microsoft/vscode-python/issues/25904"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:691f1734-41cc-fafa-2050-c3dcae08b9ac
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC9C4:30751:1BBD82:2730D1:6AFDFBED
html-safe-nonce1a587ff9af64df639528bb4a5a967f8fdea5a60fb00b6adb5784fa415f3248c3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUM0OjMwNzUxOjFCQkQ4MjoyNzMwRDE6NkFGREZCRUQiLCJ2aXNpdG9yX2lkIjoiMzk3OTE1MjUyODU0NDQ5NjYyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacc314f0e56495eb5103d056eadcf98a5b267fabb4392c19f7aac2e5c9607bd4cf
hovercard-subject-tagissue:4232233143
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/vscode-python/25904/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e3bdf0e2e1f5b7680b300b1fb120b46bc63cdc8f5ae15c97a3ce596658e0d975/microsoft/vscode-python/issues/25904
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e3bdf0e2e1f5b7680b300b1fb120b46bc63cdc8f5ae15c97a3ce596658e0d975/microsoft/vscode-python/issues/25904
og:image:altThe following way is the recommended method to run PYTHONSTARTUP in a console, the type of which inherits from code.InteractiveConsole: if path := os.getenv('PYTHONSTARTUP'): with tokenize.open(pat...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejonathandung
hostnamegithub.com
expected-hostnamegithub.com
Noneee3343385a977757dd145b28fabf4a119780f2615a5a36c5a89f66c9b3b5616d
turbo-cache-controlno-preview
go-importgithub.com/microsoft/vscode-python git https://github.com/microsoft/vscode-python.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id106462765
octolytics-dimension-repository_nwomicrosoft/vscode-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forktrue
octolytics-dimension-repository_parent_id49946255
octolytics-dimension-repository_parent_nwoDonJayamanne/pythonVSCode
octolytics-dimension-repository_network_root_id49946255
octolytics-dimension-repository_network_root_nwoDonJayamanne/pythonVSCode
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release43ae91995f6e2d5ff7a491f3de438f1f723adeaa
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/vscode-python/issues/25904#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fvscode-python%2Fissues%2F25904
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fvscode-python%2Fissues%2F25904
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2Fvscode-python
Reloadhttps://github.com/microsoft/vscode-python/issues/25904
Reloadhttps://github.com/microsoft/vscode-python/issues/25904
Reloadhttps://github.com/microsoft/vscode-python/issues/25904
microsofthttps://github.com/microsoft
vscode-pythonhttps://github.com/microsoft/vscode-python
Codehttps://github.com/microsoft/vscode-python
Issues345 (345)https://github.com/microsoft/vscode-python/issues
Pull requests54 (54)https://github.com/microsoft/vscode-python/pulls
Discussionshttps://github.com/microsoft/vscode-python/discussions
Actionshttps://github.com/microsoft/vscode-python/actions
Wikihttps://github.com/microsoft/vscode-python/wiki
Security and quality2 (2)https://github.com/microsoft/vscode-python/security
Insightshttps://github.com/microsoft/vscode-python/insights
https://github.com/microsoft/vscode-python
New issuehttps://github.com/login?return_to=https://github.com/microsoft/vscode-python/issues/25904
New issuehttps://github.com/login?return_to=https://github.com/microsoft/vscode-python/issues/25904
Avoid loading sys and platform modules into namespace when running PYTHONSTARTUP in integrated terminalhttps://github.com/microsoft/vscode-python/issues/25904#top
https://github.com/anthonykim1
feature-requestRequest for new features or functionalityhttps://github.com/microsoft/vscode-python/issues?q=state%3Aopen%20label%3A%22feature-request%22
triage-neededNeeds assignment to the proper sub-teamhttps://github.com/microsoft/vscode-python/issues?q=state%3Aopen%20label%3A%22triage-needed%22
https://github.com/jonathandung
Jonathan Dung (jonathandung)https://github.com/jonathandung
on Apr 9, 2026https://github.com/microsoft/vscode-python/issues/25904#issue-4232233143
pythonrc.pyhttps://github.com/microsoft/vscode-python/blob/main/python_files/pythonrc.py
Jonathan Dung (jonathandung)https://github.com/jonathandung
feature-requestRequest for new features or functionalityhttps://github.com/microsoft/vscode-python/issues?q=state%3Aopen%20label%3A%22feature-request%22
on Apr 9, 2026https://github.com/microsoft/vscode-python/issues/25904#event-24335581120
github-actionshttps://github.com/apps/github-actions
triage-neededNeeds assignment to the proper sub-teamhttps://github.com/microsoft/vscode-python/issues?q=state%3Aopen%20label%3A%22triage-needed%22
on Apr 9, 2026https://github.com/microsoft/vscode-python/issues/25904#event-24335594786
Eleanor Boyd (eleanorjboyd)https://github.com/eleanorjboyd
Anthony Kim (anthonykim1)https://github.com/anthonykim1
on May 1, 2026https://github.com/microsoft/vscode-python/issues/25904#event-25075076156
https://github.com/edvilme
Eduardo Villalpando Mello (edvilme)https://github.com/edvilme
on Sep 10, 2026https://github.com/microsoft/vscode-python/issues/25904#issuecomment-5627012376
#26148https://github.com/microsoft/vscode-python/pull/26148
Eduardo Villalpando Mello (edvilme)https://github.com/edvilme
duplicatehttps://github.com/microsoft/vscode-python/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Aduplicate
Avoid leaking variables in PyREPL #26147https://github.com/microsoft/vscode-python/issues/26147
on Sep 10, 2026https://github.com/microsoft/vscode-python/issues/25904#event-30938157727
https://github.com/jonathandung
Jonathan Dung (jonathandung)https://github.com/jonathandung
on Sep 11, 2026https://github.com/microsoft/vscode-python/issues/25904#issuecomment-5627320020
https://github.com/edvilme
Eduardo Villalpando Mello (edvilme)https://github.com/edvilme
on Sep 14, 2026https://github.com/microsoft/vscode-python/issues/25904#issuecomment-5659617868
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/vscode-python/issues/25904
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/vscode-python/issues/25904
Anthony Kim (anthonykim1)https://github.com/anthonykim1
feature-requestRequest for new features or functionalityhttps://github.com/microsoft/vscode-python/issues?q=state%3Aopen%20label%3A%22feature-request%22
triage-neededNeeds assignment to the proper sub-teamhttps://github.com/microsoft/vscode-python/issues?q=state%3Aopen%20label%3A%22triage-needed%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.