refac
This commit is contained in:
8
main.py
8
main.py
@@ -133,15 +133,17 @@ def _restore_stdout() -> None:
|
|||||||
if captured_stdout is _original_stdout:
|
if captured_stdout is _original_stdout:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
captured = ""
|
||||||
required_stringio_methods = ("getvalue", "write", "flush")
|
required_stringio_methods = ("getvalue", "write", "flush")
|
||||||
if not all(
|
try:
|
||||||
|
if all(
|
||||||
callable(getattr(captured_stdout, method_name, None))
|
callable(getattr(captured_stdout, method_name, None))
|
||||||
for method_name in required_stringio_methods
|
for method_name in required_stringio_methods
|
||||||
):
|
):
|
||||||
return
|
|
||||||
|
|
||||||
captured = captured_stdout.getvalue()
|
captured = captured_stdout.getvalue()
|
||||||
|
finally:
|
||||||
sys.stdout = _original_stdout
|
sys.stdout = _original_stdout
|
||||||
|
|
||||||
if captured:
|
if captured:
|
||||||
print(captured, end="", file=sys.stderr)
|
print(captured, end="", file=sys.stderr)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user