X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=string_utils.py;h=adfb149204b525327fc854fc56d6ab5645e321bc;hb=d7d135be2f9dbb2d8398d7258f8bac24b4205a2b;hp=d75c6ba1aca2c559ed4254d535747c54f4719bf5;hpb=e8fbbb7306430478dec55d2c963eed116d8330cc;p=python_utils.git diff --git a/string_utils.py b/string_utils.py index d75c6ba..adfb149 100644 --- a/string_utils.py +++ b/string_utils.py @@ -40,7 +40,7 @@ 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 +1208,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 +1228,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: