gh-119102: Fix error being thrown on quit when REPL has TERM=dumb by eugenetriguba · Pull Request #119328 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Lib/_pyrepl/__main__.py
6 changes: 6 additions & 0 deletions Lib/_pyrepl/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

IS_PYREPL_SUPPORTED_PLATFORM = sys.platform != "win32"

# Note: This will be updated on REPL startup based on additional checks.
CAN_USE_PYREPL = IS_PYREPL_SUPPORTED_PLATFORM
2 changes: 1 addition & 1 deletion Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def register_readline():
pass

def write_history():
from _pyrepl.__main__ import CAN_USE_PYREPL
from _pyrepl.env import CAN_USE_PYREPL
try:
if os.getenv("PYTHON_BASIC_REPL") or not CAN_USE_PYREPL:
readline.write_history_file(history)
Expand Down
14 changes: 12 additions & 2 deletions Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):

# Set TERM=vt100, for the rationale see the comments in spawn_python() of
# test.support.script_helper.
env = kw.setdefault('env', dict(os.environ))
env['TERM'] = 'vt100'
if "env" not in kw:
env = kw.setdefault('env', dict(os.environ))
env['TERM'] = 'vt100'
return subprocess.Popen(cmd_line,
executable=sys.executable,
text=True,
Expand Down Expand Up @@ -198,6 +199,15 @@ def bar(x):
def test_asyncio_repl_is_ok(self):
assert_python_ok("-m", "asyncio")

def test_repl_with_dumb_term_exits_cleanly(self):
env = dict(os.environ)
env.update({"TERM": "dumb"})
p = spawn_repl(env=env)
p.stdin.write("quit()\n")
output = kill_python(p)
self.assertEqual(p.returncode, 0)
self.assertNotIn("Exception", output)
self.assertNotIn("Traceback", output)


class TestInteractiveModeSyntaxErrors(unittest.TestCase):
Expand Down