Adds type annotations.
authorScott Gasch <[email protected]>
Tue, 13 Jun 2023 04:23:47 +0000 (21:23 -0700)
committerScott Gasch <[email protected]>
Tue, 13 Jun 2023 04:23:47 +0000 (21:23 -0700)
src/pyutils/argparse_utils.py

index 97a57746bdedadc2bae1f8c35ab0d7818b33925c..6920bfa2ef983810d7cda561bb78cc0bc1634c02 100644 (file)
@@ -18,7 +18,7 @@ import argparse
 import datetime
 import logging
 import os
-from typing import Any
+from typing import Any, Optional
 
 from overrides import overrides
 
@@ -51,7 +51,14 @@ class ActionNoYes(argparse.Action):
 
     """
 
-    def __init__(self, option_strings, dest, default=None, required=False, help=None):
+    def __init__(
+        self,
+        option_strings: str,
+        dest: str,
+        default: Optional[str] = None,
+        required: bool = False,
+        help: Optional[str] = None,
+    ):
         if default is None:
             msg = "You must provide a default with Yes/No action"
             logger.critical(msg)
@@ -79,11 +86,12 @@ class ActionNoYes(argparse.Action):
         )
 
     @overrides
-    def __call__(self, parser, namespace, values, option_strings=None):
-        if option_strings.startswith("--no-") or option_strings.startswith("--no_"):
-            setattr(namespace, self.dest, False)
-        else:
-            setattr(namespace, self.dest, True)
+    def __call__(self, parser, namespace, values, option_strings: Optional[str] = None):
+        if option_strings is not None:
+            if option_strings.startswith("--no-") or option_strings.startswith("--no_"):
+                setattr(namespace, self.dest, False)
+            else:
+                setattr(namespace, self.dest, True)
 
 
 def valid_bool(v: Any) -> bool: