Skip to content

Commit 161f8b9

Browse files
committed
gh-119102: Fix REPL for dumb terminal
Move CAN_USE_PYREPL variable from _pyrepl.__main__ to _pyrepl and rename it to _CAN_USE_PYREPL. Use the variable in the site module to decide if _pyrepl.write_history_file() can be used.
1 parent 72d07dd commit 161f8b9

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Lib/_pyrepl/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
1818
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1919
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20+
21+
import sys
22+
23+
_CAN_USE_PYREPL = sys.platform != "win32"

Lib/_pyrepl/__main__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import os
22
import sys
3-
4-
CAN_USE_PYREPL = sys.platform != "win32"
3+
import _pyrepl
54

65

76
def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
8-
global CAN_USE_PYREPL
9-
if not CAN_USE_PYREPL:
7+
if not _pyrepl._CAN_USE_PYREPL:
108
return sys._baserepl()
119

1210
startup_path = os.getenv("PYTHONSTARTUP")
@@ -38,7 +36,7 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
3836
msg = f"warning: can't use pyrepl: {e}"
3937
trace(msg)
4038
print(msg, file=sys.stderr)
41-
CAN_USE_PYREPL = False
39+
_pyrepl._CAN_USE_PYREPL = False
4240
if run_interactive is None:
4341
return sys._baserepl()
4442
return run_interactive(mainmodule)

Lib/site.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,9 @@ def register_readline():
523523
pass
524524

525525
def write_history():
526+
import _pyrepl
526527
try:
527-
if os.getenv("PYTHON_BASIC_REPL"):
528+
if os.getenv("PYTHON_BASIC_REPL") or not _pyrepl._CAN_USE_PYREPL:
528529
readline.write_history_file(history)
529530
else:
530531
_pyrepl.readline.write_history_file(history)

0 commit comments

Comments
 (0)