Skip to content

Commit

Permalink
adding code to support optional type appreviation request
Browse files Browse the repository at this point in the history
Author:    Damien Burks <damien@damienjburks.com>
  • Loading branch information
Damien Burks authored and damienjburks committed Jan 24, 2022
1 parent ed44d8b commit 7eb9a9e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fire/inspectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import types

from fire import docstrings
from typing import get_args

import six

Expand Down Expand Up @@ -143,7 +144,7 @@ def Py3GetFullArgSpec(fn):

if sig.return_annotation is not sig.empty:
annotations['return'] = sig.return_annotation

for param in sig.parameters.values():
kind = param.kind
name = param.name
Expand All @@ -165,6 +166,10 @@ def Py3GetFullArgSpec(fn):
varkw = name
if param.annotation is not param.empty:
annotations[name] = param.annotation
if "Union" in str(annotations[name]):
union_type_tuple = get_args(annotations[name])
annotations[name] = union_type_tuple[0]

# pylint: enable=protected-access

if not kwdefaults:
Expand Down

0 comments on commit 7eb9a9e

Please sign in to comment.