Skip to content

Commit

Permalink
Wrap issubclass check in try/except
Browse files Browse the repository at this point in the history
  • Loading branch information
jorwoods committed Aug 1, 2022
1 parent 2e873b9 commit 803638f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = argsubparse
version = 0.0.12
version = 0.0.13
author = Jordan Woods
author_email = jor.e.woods@gmail.com
description = Dynamically build argparse subparsers
Expand Down
14 changes: 8 additions & 6 deletions src/argsubparse/argsubparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ def create_subparser(
if not short_option.startswith("-"):
short_option = f"-{short_option}"
arg_name = (short_option, f"--{k}")

if issubclass(v.annotation, bool):
if v.default is not inspect._empty:
arg_params["action"] = "store_false" if v.default else "store_true"
else:
arg_params["action"] = "store_true"
try:
if issubclass(v.annotation, bool):
if v.default is not inspect._empty:
arg_params["action"] = "store_false" if v.default else "store_true"
else:
arg_params["action"] = "store_true"
except TypeError:
pass

function_parser.add_argument(*arg_name, **arg_params)

Expand Down

0 comments on commit 803638f

Please sign in to comment.