summaryrefslogtreecommitdiff
path: root/string_utils.py
diff options
context:
space:
mode:
authorScott <[email protected]>2022-01-31 21:03:41 -0800
committerScott <[email protected]>2022-01-31 21:03:41 -0800
commite224aee343a337beefc61acdfa263c88f0bde312 (patch)
tree132e2bdaa8bb2b9762098b94819a9ba341ee456e /string_utils.py
parente70297b7e29a07457d6c7195425e734a1290abeb (diff)
Clean up mypy type checker errors.
Diffstat (limited to 'string_utils.py')
-rw-r--r--string_utils.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/string_utils.py b/string_utils.py
index 9f67207..991793d 100644
--- a/string_utils.py
+++ b/string_utils.py
@@ -27,7 +27,7 @@ This class is based on: https://github.com/daveoncode/python-string-utils.
"""
import base64
-import contextlib
+import contextlib # type: ignore
import datetime
import io
from itertools import zip_longest
@@ -1241,7 +1241,7 @@ class SprintfStdout(object):
def __init__(self) -> None:
self.destination = io.StringIO()
- self.recorder = None
+ self.recorder: contextlib.redirect_stdout
def __enter__(self) -> Callable[[], str]:
self.recorder = contextlib.redirect_stdout(self.destination)
@@ -1338,7 +1338,7 @@ def trigrams(txt: str):
def shuffle_columns_into_list(
- input_lines: Iterable[str], column_specs: Iterable[Iterable[int]], delim=''
+ input_lines: Sequence[str], column_specs: Iterable[Iterable[int]], delim=''
) -> Iterable[str]:
"""Helper to shuffle / parse columnar data and return the results as a
list. The column_specs argument is an iterable collection of
@@ -1368,7 +1368,7 @@ def shuffle_columns_into_list(
def shuffle_columns_into_dict(
- input_lines: Iterable[str],
+ input_lines: Sequence[str],
column_specs: Iterable[Tuple[str, Iterable[int]]],
delim='',
) -> Dict[str, str]:
@@ -1425,7 +1425,7 @@ def to_ascii(x: str):
raise Exception('to_ascii works with strings and bytes')
-def to_base64(txt: str, *, encoding='utf-8', errors='surrogatepass') -> str:
+def to_base64(txt: str, *, encoding='utf-8', errors='surrogatepass') -> bytes:
"""Encode txt and then encode the bytes with a 64-character
alphabet. This is compatible with uudecode.
@@ -1458,7 +1458,7 @@ def is_base64(txt: str) -> bool:
return True
-def from_base64(b64: str, encoding='utf-8', errors='surrogatepass') -> str:
+def from_base64(b64: bytes, encoding='utf-8', errors='surrogatepass') -> str:
"""Convert base64 encoded string back to normal strings.
>>> from_base64(b'aGVsbG8/\\n')
@@ -1529,7 +1529,7 @@ def from_bitstring(bits: str, encoding='utf-8', errors='surrogatepass') -> str:
return n.to_bytes((n.bit_length() + 7) // 8, 'big').decode(encoding, errors) or '\0'
-def ip_v4_sort_key(txt: str) -> Tuple[int]:
+def ip_v4_sort_key(txt: str) -> Optional[Tuple[int, ...]]:
"""Turn an IPv4 address into a tuple for sorting purposes.
>>> ip_v4_sort_key('10.0.0.18')
@@ -1546,7 +1546,7 @@ def ip_v4_sort_key(txt: str) -> Tuple[int]:
return tuple([int(x) for x in txt.split('.')])
-def path_ancestors_before_descendants_sort_key(volume: str) -> Tuple[str]:
+def path_ancestors_before_descendants_sort_key(volume: str) -> Tuple[str, ...]:
"""Chunk up a file path so that parent/ancestor paths sort before
children/descendant paths.