Skip to content

Commit 378c2c7

Browse files
committed
Move fix to main.py
1 parent 0d2ff21 commit 378c2c7

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎Lib/_pyrepl/main.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
try:
1010
if sys.platform == "win32" and sys.getwindowsversion().build < 10586:
1111
raise RuntimeError("Windows 10 TH2 or later required")
12-
if not os.isatty(sys.stdin.fileno()):
12+
stdin_fd = sys.stdin.fileno()
13+
if (
14+
not os.isatty(stdin_fd)
15+
or (
16+
sys.platform == "win32"
17+
and os.device_encoding(stdin_fd) is None
18+
)
19+
):
1320
raise OSError(errno.ENOTTY, "tty required", "stdin")
1421
from .simple_interact import check
1522
if err := check():

‎Lib/_pyrepl/readline.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,7 @@ def _setup(namespace: Mapping[str, Any]) -> None:
612612
f_out = sys.stdout.fileno()
613613
except (AttributeError, ValueError):
614614
return
615-
if (
616-
not os.isatty(f_in)
617-
or not os.isatty(f_out)
618-
or os.device_encoding(f_in) is None
619-
or os.device_encoding(f_out) is None
620-
):
615+
if not os.isatty(f_in) or not os.isatty(f_out):
621616
return
622617

623618
_wrapper.f_in = f_in

‎Lib/test/test_pyrepl/test_pyrepl.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def test_get_completions_sorts_colored_matches_by_visible_text(self):
10991099
)
11001100

11011101

1102-
class TestPyReplReadlineSetup(TestCase):
1102+
class TestPyReplMain(TestCase):
11031103
@skipUnless(has_subprocess_support, "test requires subprocess support")
11041104
@skipUnless(sys.platform == "win32", "Windows-specific test")
11051105
def test_nul_stdin_exits_cleanly(self):
@@ -1113,7 +1113,10 @@ def test_nul_stdin_exits_cleanly(self):
11131113
)
11141114

11151115
self.assertEqual(proc.returncode, 0, proc.stderr)
1116+
self.assertIn("tty required", proc.stderr)
1117+
11161118

1119+
class TestPyReplReadlineSetup(TestCase):
11171120
def test_setup_ignores_basic_completer_env_when_env_is_disabled(self):
11181121
class FakeFancyCompleter:
11191122
def __init__(self, namespace):
@@ -1143,11 +1146,6 @@ class FakeBasicCompleter(FakeFancyCompleter):
11431146
patch.object(pyrepl_readline.sys, "stdout", stdout),
11441147
patch.object(pyrepl_readline.sys, "flags", Mock(ignore_environment=True)),
11451148
patch.object(pyrepl_readline.os, "isatty", return_value=True),
1146-
patch.object(
1147-
pyrepl_readline.os,
1148-
"device_encoding",
1149-
return_value="utf-8",
1150-
),
11511149
patch.object(pyrepl_readline.os, "getenv") as mock_getenv,
11521150
patch("builtins.input", lambda prompt="": prompt),
11531151
):

0 commit comments

Comments
 (0)