This commit is contained in:
Taylor Wilsdon
2026-03-17 10:34:30 -04:00
parent 16ce566d88
commit 96df53c5e9

View File

@@ -133,15 +133,17 @@ def _restore_stdout() -> None:
if captured_stdout is _original_stdout:
return
captured = ""
required_stringio_methods = ("getvalue", "write", "flush")
if not all(
try:
if all(
callable(getattr(captured_stdout, method_name, None))
for method_name in required_stringio_methods
):
return
captured = captured_stdout.getvalue()
finally:
sys.stdout = _original_stdout
if captured:
print(captured, end="", file=sys.stderr)