import unicodedata
import warnings
from itertools import zip_longest
-from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple
+from typing import Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple
from uuid import uuid4
import list_utils
return ret
-class SprintfStdout(object):
+class SprintfStdout(contextlib.AbstractContextManager):
"""
A context manager that captures outputs to stdout.
self.recorder.__enter__()
return lambda: self.destination.getvalue()
- def __exit__(self, *args) -> None:
+ def __exit__(self, *args) -> Literal[False]:
self.recorder.__exit__(*args)
self.destination.seek(0)
- return None # don't suppress exceptions
+ return False
def capitalize_first_letter(txt: str) -> str: