Skip to content

Commit ef08776

Browse files
committed
Fixing boxed optional types for python 3.6
1 parent 5198e0b commit ef08776

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tap/tap.py

+11
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ def _add_argument(self, *name_or_flags, **kwargs) -> None:
173173

174174
if len(var_args) > 0:
175175
var_type = get_args(var_type)[0]
176+
177+
# If var_type is tuple as in Python 3.6, change to a typing type
178+
# (e.g., (typing.List, <class 'bool'>) ==> typing.List[bool])
179+
if isinstance(var_type, tuple):
180+
var_type = var_type[0][var_type[1:]]
181+
176182
explicit_bool = True
177183

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

406+
# If var_type is tuple as in Python 3.6, change to a typing type
407+
# (e.g., (typing.Tuple, <class 'bool'>) ==> typing.Tuple)
408+
if isinstance(var_type, tuple):
409+
var_type = var_type[0]
410+
400411
if var_type in (Set, set):
401412
value = set(value)
402413
elif var_type in (Tuple, tuple):

0 commit comments

Comments
 (0)