X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=string_utils.py;h=4bec031738e989d10507992387e18aa47996da8e;hb=f2600f30801c849fc1d139386e3ddc3c9eb43e30;hp=d75c6ba1aca2c559ed4254d535747c54f4719bf5;hpb=e8fbbb7306430478dec55d2c963eed116d8330cc;p=python_utils.git diff --git a/string_utils.py b/string_utils.py index d75c6ba..4bec031 100644 --- a/string_utils.py +++ b/string_utils.py @@ -40,7 +40,17 @@ import string 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 @@ -1208,7 +1218,7 @@ def sprintf(*args, **kwargs) -> str: return ret -class SprintfStdout(object): +class SprintfStdout(contextlib.AbstractContextManager): """ A context manager that captures outputs to stdout. @@ -1228,10 +1238,10 @@ class SprintfStdout(object): 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: