From 1377a05d6c3d7bb2fec9a7be5b5fd94f6ed30f48 Mon Sep 17 00:00:00 2001 From: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> Date: Tue, 29 Sep 2026 12:29:19 +0530 Subject: [PATCH 1/2] Guard import when standard input is unavailable --- click_repl/globals_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/click_repl/globals_.py b/click_repl/globals_.py index 3e1f49b..cc4586a 100644 --- a/click_repl/globals_.py +++ b/click_repl/globals_.py @@ -9,7 +9,7 @@ from .core import ReplContext -ISATTY = sys.stdin.isatty() +ISATTY = sys.stdin is not None and sys.stdin.isatty() @overload From 86f363e9e72ffce142065df8b6047c3f35bc453a Mon Sep 17 00:00:00 2001 From: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> Date: Tue, 29 Sep 2026 12:29:29 +0530 Subject: [PATCH 2/2] Test import without standard input Add a test to verify package import without stdin. --- tests/test_import.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_import.py diff --git a/tests/test_import.py b/tests/test_import.py new file mode 100644 index 0000000..431f5a6 --- /dev/null +++ b/tests/test_import.py @@ -0,0 +1,21 @@ +"""Importing the package must work without an attached standard input.""" + +import os +import subprocess +import sys + + +def test_import_without_stdin(): + # Closing fd 0 causes Python to expose sys.stdin as None. Test in a + # child so the test runner's own input stream remains untouched. + if os.name == "nt": + code = "import sys; sys.stdin = None; import click_repl" + result = subprocess.run([sys.executable, "-c", code], capture_output=True) + else: + result = subprocess.run( + [sys.executable, "-c", "import sys; assert sys.stdin is None; " + "import click_repl"], + capture_output=True, + preexec_fn=lambda: os.close(0), + ) + assert result.returncode == 0, result.stderr.decode(errors="replace")