From 96df53c5e9b0a231309049ae42012d2c6704845a Mon Sep 17 00:00:00 2001 From: Taylor Wilsdon Date: Tue, 17 Mar 2026 10:34:30 -0400 Subject: [PATCH] refac --- main.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 02b66e1..5051ce2 100644 --- a/main.py +++ b/main.py @@ -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( - callable(getattr(captured_stdout, method_name, None)) - for method_name in required_stringio_methods - ): - return + try: + if all( + callable(getattr(captured_stdout, method_name, None)) + for method_name in required_stringio_methods + ): + captured = captured_stdout.getvalue() + finally: + sys.stdout = _original_stdout - captured = captured_stdout.getvalue() - sys.stdout = _original_stdout if captured: print(captured, end="", file=sys.stderr)