Cleanup.
[python_utils.git] / text_utils.py
index 4384a1e6134810982e9227d2bb1dfdb517627f72..7910990f2a58ec318ba6a68a7ba9e87ff415c77b 100644 (file)
@@ -3,11 +3,12 @@
 
 """Utilities for dealing with "text"."""
 
+import contextlib
 import logging
 import math
 import sys
 from collections import defaultdict
-from typing import Dict, Generator, List, NamedTuple, Optional, Tuple
+from typing import Dict, Generator, List, Literal, NamedTuple, Optional, Tuple
 
 from ansi import fg, reset
 
@@ -261,7 +262,7 @@ def wrap_string(text: str, n: int) -> str:
     return out
 
 
-class Indenter(object):
+class Indenter(contextlib.AbstractContextManager):
     """
     with Indenter(pad_count = 8) as i:
         i.print('test')
@@ -289,10 +290,11 @@ class Indenter(object):
         self.level += 1
         return self
 
-    def __exit__(self, exc_type, exc_value, exc_tb):
+    def __exit__(self, exc_type, exc_value, exc_tb) -> Literal[False]:
         self.level -= 1
         if self.level < -1:
             self.level = -1
+        return False
 
     def print(self, *arg, **kwargs):
         import string_utils