Used isort to sort imports. Also added to the git pre-commit hook.
[python_utils.git] / argparse_utils.py
index 1c61b2460650c11872cbaaabf4e7f5a689be746c..5a270f6ef22c1845be1bd6c59ab7fde1cb4cfe21 100644 (file)
@@ -8,7 +8,6 @@ from typing import Any
 
 from overrides import overrides
 
-
 # This module is commonly used by others in here and should avoid
 # taking any unnecessary dependencies back on them.
 
@@ -16,14 +15,7 @@ logger = logging.getLogger(__name__)
 
 
 class ActionNoYes(argparse.Action):
-    def __init__(
-            self,
-            option_strings,
-            dest,
-            default=None,
-            required=False,
-            help=None
-    ):
+    def __init__(self, option_strings, dest, default=None, required=False, help=None):
         if default is None:
             msg = 'You must provide a default with Yes/No action'
             logger.critical(msg)
@@ -47,15 +39,12 @@ class ActionNoYes(argparse.Action):
             const=None,
             default=default,
             required=required,
-            help=help
+            help=help,
         )
 
     @overrides
     def __call__(self, parser, namespace, values, option_strings=None):
-        if (
-                option_strings.startswith('--no-') or
-                option_strings.startswith('--no_')
-        ):
+        if option_strings.startswith('--no-') or option_strings.startswith('--no_'):
             setattr(namespace, self.dest, False)
         else:
             setattr(namespace, self.dest, True)
@@ -89,6 +78,7 @@ def valid_bool(v: Any) -> bool:
     if isinstance(v, bool):
         return v
     from string_utils import to_bool
+
     try:
         return to_bool(v)
     except Exception:
@@ -110,6 +100,7 @@ def valid_ip(ip: str) -> str:
 
     """
     from string_utils import extract_ip_v4
+
     s = extract_ip_v4(ip.strip())
     if s is not None:
         return s
@@ -136,6 +127,7 @@ def valid_mac(mac: str) -> str:
 
     """
     from string_utils import extract_mac_address
+
     s = extract_mac_address(mac)
     if s is not None:
         return s
@@ -206,6 +198,7 @@ def valid_date(txt: str) -> datetime.date:
     -ANYTHING-
     """
     from string_utils import to_date
+
     date = to_date(txt)
     if date is not None:
         return date
@@ -228,6 +221,7 @@ def valid_datetime(txt: str) -> datetime.datetime:
     -ANYTHING-
     """
     from string_utils import to_datetime
+
     dt = to_datetime(txt)
     if dt is not None:
         return dt
@@ -250,6 +244,7 @@ def valid_duration(txt: str) -> datetime.timedelta:
 
     """
     from datetime_utils import parse_duration
+
     try:
         secs = parse_duration(txt)
     except Exception as e:
@@ -260,5 +255,6 @@ def valid_duration(txt: str) -> datetime.timedelta:
 
 if __name__ == '__main__':
     import doctest
+
     doctest.ELLIPSIS_MARKER = '-ANYTHING-'
     doctest.testmod()