Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding code to support optional type abbreviation request #380

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion fire/inspectutils.py
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,6 @@ 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 +165,8 @@ def Py3GetFullArgSpec(fn):
varkw = name
if param.annotation is not param.empty:
annotations[name] = param.annotation
if "Optional" in str(annotations[name]) or "Union" in str(annotations[name]):
annotations[name] = ", ".join(x.__name__ for x in get_args(annotations[name]))
# pylint: enable=protected-access

if not kwdefaults:
Expand Down
2 changes: 1 addition & 1 deletion fire/test_components.py
Expand Up @@ -98,7 +98,7 @@ def double(self, count=0):
count: Input number that you want to double.

Returns:
A number that is the double of count.s
A number that is the double of count.
"""
return 2 * count

Expand Down
4 changes: 2 additions & 2 deletions fire/test_components_py3.py
Expand Up @@ -67,7 +67,7 @@ def double(self, count: float) -> float:
count: Input number that you want to double.

Returns:
A number that is the double of count.s
A number that is the double of count.
"""
return 2 * count

Expand All @@ -89,7 +89,7 @@ def double(self, count: float = 0) -> float:
count: Input number that you want to double.

Returns:
A number that is the double of count.s
A number that is the double of count.
"""
return 2 * count

Expand Down