Skip to content

gh-134300: Remove idlelib from the path of the IDLE user process#152739

Merged
terryjreedy merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-134300-idlelib-syspath
Jul 1, 2026
Merged

gh-134300: Remove idlelib from the path of the IDLE user process#152739
terryjreedy merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-134300-idlelib-syspath

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 1, 2026

Copy link
Copy Markdown
Member

When idle.py is run as a script, its directory (.../idlelib) is placed on sys.path[0]. ModifiedInterpreter.transfer_path() then sends the whole GUI sys.path to the user subprocess (replacing its sys.path), so user code could import idlelib submodules as top-level modules, e.g. import help silently imports idlelib.help. A subissue of #69674.

transfer_path() now removes the idlelib directory from the transferred path. Only that entry is removed, so import idlelib.run and the other idlelib modules the subprocess needs still resolve via the Lib parent directory; as Terry noted in the issue, idlelib.run runs fine without idlelib on the path.

The removal is factored into a module-level fix_user_path() with a non-GUI unit test.

🤖 Generated with Claude Code

The idlelib directory ends up on sys.path when idle.py is run as a script,
and it was passed to the user process, where it let user code import
idlelib submodules as top-level modules, such as "import help".
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 1, 2026

@terryjreedy terryjreedy 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.

I agree that removing idlelib in pyshell before sending the path is better than in run after receiving it. So is checking all items rather than just the first 2. (Both my ideas initially.) Thanks for the PR.

@terryjreedy terryjreedy merged commit 3f5491a into python:main Jul 1, 2026
103 of 107 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

GH-152807 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 1, 2026
@bedevere-app

bedevere-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

GH-152808 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 1, 2026
@bedevere-app

bedevere-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

GH-152809 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 1, 2026
@serhiy-storchaka serhiy-storchaka deleted the gh-134300-idlelib-syspath branch July 1, 2026 16:47
terryjreedy pushed a commit that referenced this pull request Jul 1, 2026
…ss (GH-152739) (#152809)

gh-134300: Remove idlelib from the path of the IDLE user process (GH-152739)

The idlelib directory ends up on sys.path when idle.py is run as a script,
and it was passed to the user process, where it let user code import
idlelib submodules as top-level modules, such as "import help".
(cherry picked from commit 3f5491a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
terryjreedy pushed a commit that referenced this pull request Jul 1, 2026
…ss (GH-152739) (#152807)

gh-134300: Remove idlelib from the path of the IDLE user process (GH-152739)

The idlelib directory ends up on sys.path when idle.py is run as a script,
and it was passed to the user process, where it let user code import
idlelib submodules as top-level modules, such as "import help".
(cherry picked from commit 3f5491a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
terryjreedy pushed a commit that referenced this pull request Jul 1, 2026
…ss (GH-152739) (#152808)

gh-134300: Remove idlelib from the path of the IDLE user process (GH-152739)

The idlelib directory ends up on sys.path when idle.py is run as a script,
and it was passed to the user process, where it let user code import
idlelib submodules as top-level modules, such as "import help".
(cherry picked from commit 3f5491a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants