summaryrefslogtreecommitdiff
path: root/asciidoc/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'asciidoc/utils.py')
-rw-r--r--asciidoc/utils.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/asciidoc/utils.py b/asciidoc/utils.py
index fee2c00..82863c3 100644
--- a/asciidoc/utils.py
+++ b/asciidoc/utils.py
@@ -3,7 +3,7 @@ import math
import os
import re
import time
-from typing import Optional
+from typing import List, Optional, Tuple, Union
import unicodedata
@@ -36,7 +36,7 @@ def assign(dst, src):
setattr(dst, a, v)
-def strip_quotes(s):
+def strip_quotes(s: str) -> str:
"""Trim white space and, if necessary, quote characters from s."""
s = s.strip()
# Strip quotation mark characters from quoted strings.
@@ -54,7 +54,7 @@ def is_re(s) -> bool:
return False
-def re_join(relist):
+def re_join(relist: List) -> List:
"""Join list of regular expressions re1,re2,... to single regular
expression (re1)|(re2)|..."""
if len(relist) == 0:
@@ -68,7 +68,7 @@ def re_join(relist):
return result
-def lstrip_list(s):
+def lstrip_list(s: Union[List, Tuple]) -> Union[List, Tuple]:
"""
Return list with empty items from start of list removed.
"""
@@ -80,7 +80,7 @@ def lstrip_list(s):
return s[i:]
-def rstrip_list(s):
+def rstrip_list(s: Union[List, Tuple]) -> Union[List, Tuple]:
"""
Return list with empty items from end of list removed.
"""
@@ -92,7 +92,7 @@ def rstrip_list(s):
return s[:i + 1]
-def strip_list(s):
+def strip_list(s: Union[List, Tuple]) -> Union[List, Tuple]:
"""
Return list with empty items from start and end of list removed.
"""
@@ -133,7 +133,7 @@ def dovetail_tags(stag, content, etag):
return dovetail(dovetail(stag, content), etag)
-def py2round(n, d=0):
+def py2round(n: Union[float, int], d: int = 0) -> int:
"""Utility function to get python2 rounding in python3. Python3 changed it such that
given two equally close multiples, it'll round towards the even choice. For example,
round(42.5) == 42 instead of the expected round(42.5) == 43). This function gives us
@@ -155,14 +155,14 @@ east_asian_widths = {
column widths."""
-def column_width(s):
+def column_width(s: str) -> int:
width = 0
for c in s:
width += east_asian_widths[unicodedata.east_asian_width(c)]
return width
-def date_time_str(t):
+def date_time_str(t: float) -> Tuple[str, str]:
"""Convert seconds since the Epoch to formatted local date and time strings."""
source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
if source_date_epoch is not None: