Skip to content

gh-70331: Protect IDLE's imports from user files in the current directory - #157643

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-70331-shadow-stdlib
Open

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-70331-shadow-stdlib

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

A user file such as random.py, threading.py or tkinter.py in the directory from which IDLE was started (on Windows, "Edit with IDLE" starts it in the file's directory; on macOS, IDLE.app starts in ~/Documents) shadowed the stdlib modules imported by IDLE, in the IDLE process (python -m idlelib) or in the user process (started with python -c), and IDLE failed to start.

Now the user process is started with -P, so the current directory is not on sys.path while idlelib.run and its dependencies are imported. sys.path of the user process is set by transfer_path() later anyway, so user code sees the same sys.path as before. python -m idlelib removes the current directory from sys.path before importing idlelib.pyshell, which imports almost all of IDLE.

pyshell.main() still adds the current directory or the directories of the files to be edited to sys.path of the IDLE process, so the few modules imported later (pydoc) can still be shadowed. Changing this would change sys.path seen by user code, so it is left for a separate change.

🤖 Generated with Claude Code

… directory

Start the user process with -P, so that the current directory is not on
sys.path while idlelib.run and its dependencies are imported.  sys.path
is set later by transfer_path().

"python -m idlelib" now removes the current directory from sys.path.
@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 Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant