Skip to content

Commit

Permalink
Fixing boxed optional types for python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
swansonk14 committed Mar 27, 2021
1 parent 5198e0b commit ef08776
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tap/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def _add_argument(self, *name_or_flags, **kwargs) -> None:

if len(var_args) > 0:
var_type = get_args(var_type)[0]

# If var_type is tuple as in Python 3.6, change to a typing type
# (e.g., (typing.List, <class 'bool'>) ==> typing.List[bool])
if isinstance(var_type, tuple):
var_type = var_type[0][var_type[1:]]

explicit_bool = True

# First check whether it is a literal type or a boxed literal type
Expand Down Expand Up @@ -397,6 +403,11 @@ def parse_args(self: TapType,
if var_type is Union:
var_type = get_origin(get_args(self._annotations[variable])[0])

# If var_type is tuple as in Python 3.6, change to a typing type
# (e.g., (typing.Tuple, <class 'bool'>) ==> typing.Tuple)
if isinstance(var_type, tuple):
var_type = var_type[0]

if var_type in (Set, set):
value = set(value)
elif var_type in (Tuple, tuple):
Expand Down

0 comments on commit ef08776

Please sign in to comment.