cpython/Lib/idlelib/__main__.py
Miss Islington (bot) 6d4d828f0b
[3.13] gh-70331: Protect IDLE's imports from user files in the current directory (GH-157643) (#158036)
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-09-23 19:22:28 -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()