Skip to content

Commit eb97b2d

Browse files
committed
gh-125140: Remove the current directory from sys.path when using pyrepl
Signed-off-by: Pablo Galindo <[email protected]>
1 parent f2cb399 commit eb97b2d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Lib/site.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,21 @@ def register_readline():
497497
PYTHON_BASIC_REPL = False
498498

499499
import atexit
500+
import sys
500501
try:
501502
import readline
502503
import rlcompleter # noqa: F401
503504
if PYTHON_BASIC_REPL:
504505
CAN_USE_PYREPL = False
505506
else:
506-
import _pyrepl.readline
507-
import _pyrepl.unix_console
508-
from _pyrepl.main import CAN_USE_PYREPL
507+
original_path = sys.path
508+
sys.path = [p for p in original_path if p != '']
509+
try:
510+
import _pyrepl.readline
511+
import _pyrepl.unix_console
512+
from _pyrepl.main import CAN_USE_PYREPL
513+
finally:
514+
sys.path = original_path
509515
except ImportError:
510516
return
511517

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the current directory from sys.path when using pyrepl

0 commit comments

Comments
 (0)