cpython/Lib/idlelib/__main__.py
Miss Islington (bot) 7a563e3f98
[3.15] gh-70331: Protect IDLE's imports from user files in the current directory (GH-157643) (#158034)
gh-70331: Protect IDLE's imports from user files in the current directory (GH-157643)

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().  Protect __main__, idle, and pyshell entry points.
(cherry picked from commit 6893326350)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-10-09 17:22:45 -04:00

14 lines
296 B
Python

"""
IDLE main entry point
Run IDLE as python -m idlelib
"""
import sys
if not sys.flags.safe_path:
# Remove the current directory, prepended by "python -m", so that
# user files do not shadow IDLE's imports (gh-70331).
del sys.path[0]
import idlelib.pyshell
idlelib.pyshell.main()