Clean up, remove compat with py < 3.6
[pyi2ncommon] / src / text_helpers.py
index a258f43..662c7b3 100644 (file)
@@ -30,10 +30,9 @@ Copyright: 2015 Intra2net AG
 CONTENTS
 ------------------------------------------------------
 This module has two parts. Part 1 includes:
-
-- head_and_tail: shows the first few and last few elements of an iterable that
-                 could potentially be pretty long
-- size_str: textual representation of data size
+    - head_and_tail: shows the first few and last few elements of an iterable that
+                     could potentially be pretty long
+    - size_str: textual representation of data size
 
 Part2 contains functions for coloring text, a poor-man's version of other
 modules like :py:mod:`colorclass` (which is now also available on Intra2net
@@ -56,10 +55,7 @@ INTERFACE
 ------------------------------------------------------
 """
 
-try:
-    from builtins import print as _builtin_print
-except ImportError:    # different name in py2
-    from __builtin__ import print as _builtin_print
+from builtins import print as _builtin_print
 
 from functools import partial
 from itertools import islice
@@ -138,7 +134,7 @@ def size_str(byte_number, is_diff=False):
 
     Rounds and shortens size to something easily human-readable like '1.5 GB'.
 
-    :param int byte_number: Number of bytes to express as text
+    :param float byte_number: Number of bytes to express as text
     :param bool is_diff: Set to True to include a '+' or '-' in output;
                          default: False
     :returns: textual representation of data
@@ -170,8 +166,7 @@ def size_str(byte_number, is_diff=False):
 
     # have an impossible amount of data.  (>1024**4 GB)
     # undo last "/factor" and show thousand-separator
-    return '{2}{0:,d} {1}B'.format(int(round(curr_num*factor)), units[-1],
-                                 sign_str)
+    return f'{sign_str}{int(round(curr_num*factor)):,d} {units[-1]}B'
 
 
 ###############################################################################
@@ -194,7 +189,7 @@ STYLE_BLINK = 5
 STYLE_REVERSE = 7
 
 
-_COLOR_TO_CODE = dict(zip([COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, \
+_COLOR_TO_CODE = dict(zip([COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
                            COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE],
                           range(8)))
 
@@ -209,13 +204,13 @@ except Exception:
 
 
 def colored(text, foreground=None, background=None, style=None):
-    """ return text with given foreground/background ANSI color escape seqence
+    """ return text with given foreground/background ANSI color escape sequence
 
     :param str text: text to color
     :param str style: one of the style constants above
     :param str foreground: one of the color constants to use for text color
                            or None to leave as-is
-    :param str foreground: one of the color constants to use for background
+    :param str background: one of the color constants to use for background
                            or None to leave as-is
     :param style: single STYLE constant or iterable of those
                   or None to leave as-is