Skip to content

Commit c7d5d1d

Browse files
pablogsalambvZeroIntensity
authored
gh-125140: Remove the current directory from sys.path when using pyrepl (GH-125212)
Signed-off-by: Pablo Galindo <[email protected]> Co-authored-by: Łukasz Langa <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
1 parent 1877543 commit c7d5d1d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Lib/site.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,14 @@ def register_readline():
503503
if PYTHON_BASIC_REPL:
504504
CAN_USE_PYREPL = False
505505
else:
506-
import _pyrepl.readline
507-
import _pyrepl.unix_console
508-
from _pyrepl.main import CAN_USE_PYREPL
506+
original_path = sys.path
507+
sys.path = [p for p in original_path if p != '']
508+
try:
509+
import _pyrepl.readline
510+
import _pyrepl.unix_console
511+
from _pyrepl.main import CAN_USE_PYREPL
512+
finally:
513+
sys.path = original_path
509514
except ImportError:
510515
return
511516

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)