gh-70331: Protect IDLE's imports from user files in the current directory - #157643
Open
serhiy-storchaka wants to merge 1 commit into
Open
serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user file such as
random.py,threading.pyortkinter.pyin 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 withpython -c), and IDLE failed to start.Now the user process is started with
-P, so the current directory is not onsys.pathwhileidlelib.runand its dependencies are imported.sys.pathof the user process is set bytransfer_path()later anyway, so user code sees the samesys.pathas before.python -m idlelibremoves the current directory fromsys.pathbefore importingidlelib.pyshell, which imports almost all of IDLE.pyshell.main()still adds the current directory or the directories of the files to be edited tosys.pathof the IDLE process, so the few modules imported later (pydoc) can still be shadowed. Changing this would changesys.pathseen by user code, so it is left for a separate change.🤖 Generated with Claude Code