Fix pytest capture import in TTY session

Guard stream reconfiguration so pytest capture objects without reconfigure support can import the code execution TTY helper while preserving UTF-8 error handling for normal streams.

Alessandro committed Jun 24, 2026 at 11:13 UTC a18a35977a0e7dd4c91e216b5a5bec1b1665d9a1
1 file changed +9 -2
plugins/_code_execution/helpers/tty_session.py
+9 -2
@@ -6,9 +6,16 @@ if _IS_WIN:
6 import msvcrt
7
8
9 +def _reconfigure_stream_errors(stream) -> None:
10 + reconfigure = getattr(stream, "reconfigure", None)
11 + if not callable(reconfigure):
12 + return
13 + reconfigure(errors="replace")
14 +
15 +
16 # Make stdin / stdout tolerant to broken UTF-8 so input() never aborts
10 -sys.stdin.reconfigure(errors="replace") # type: ignore
11 -sys.stdout.reconfigure(errors="replace") # type: ignore
17 +_reconfigure_stream_errors(sys.stdin)
18 +_reconfigure_stream_errors(sys.stdout)
19
20
21 # ──────────────────────────── PUBLIC CLASS ────────────────────────────