Skip to content
Open
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
9 changes: 8 additions & 1 deletion Lib/_pyrepl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
try:
if sys.platform == "win32" and sys.getwindowsversion().build < 10586:
raise RuntimeError("Windows 10 TH2 or later required")
if not os.isatty(sys.stdin.fileno()):
stdin_fd = sys.stdin.fileno()
if (
not os.isatty(stdin_fd)
or (
sys.platform == "win32"
and os.device_encoding(stdin_fd) is None
)
):
raise OSError(errno.ENOTTY, "tty required", "stdin")
from .simple_interact import check
if err := check():
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,23 @@ def test_get_completions_sorts_colored_matches_by_visible_text(self):
)


class TestPyReplMain(TestCase):
@skipUnless(has_subprocess_support, "test requires subprocess support")
@skipUnless(sys.platform == "win32", "Windows-specific test")
def test_nul_stdin_exits_cleanly(self):
proc = subprocess.run(
[sys.executable, "-I"],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
timeout=SHORT_TIMEOUT,
)

self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertIn("tty required", proc.stderr)


class TestPyReplReadlineSetup(TestCase):
def test_setup_ignores_basic_completer_env_when_env_is_disabled(self):
class FakeFancyCompleter:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyREPL on Windows now exits when ``NUL`` is passed as ``stdin`` instead of showing stream of tracebacks.
Loading