From b1d4e45d24d133f87c7464dd62cccd87e9e474df Mon Sep 17 00:00:00 2001 From: David Bieber Date: Thu, 17 Jun 2021 11:02:53 -0700 Subject: [PATCH 1/3] Fix typos in test component docstrings. PiperOrigin-RevId: 379999792 Change-Id: I2594db4540cfe20820951bae479d16c167ba391a adding code to support optional type appreviation request Author: Damien Burks committing latest changes for supporting python 3.9+ --- fire/inspectutils.py | 9 ++++++++- fire/test_components.py | 2 +- fire/test_components_py3.py | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fire/inspectutils.py b/fire/inspectutils.py index 0fa8e7d3..ca35bc12 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -23,6 +23,7 @@ import types from fire import docstrings +from typing import get_args import six @@ -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 @@ -165,6 +165,13 @@ 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]): + tuple_param1 = get_args(annotations[name])[0].__name__ + tuple_param2 = get_args(annotations[name])[1].__name__ + if str(tuple_param2) != "NoneType": + annotations[name] = tuple_param1 + ", " + tuple_param2 + else: + annotations[name] = tuple_param # pylint: enable=protected-access if not kwdefaults: diff --git a/fire/test_components.py b/fire/test_components.py index eee9a07c..027a6b19 100644 --- a/fire/test_components.py +++ b/fire/test_components.py @@ -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 diff --git a/fire/test_components_py3.py b/fire/test_components_py3.py index 3c21f4ba..b6c78c84 100644 --- a/fire/test_components_py3.py +++ b/fire/test_components_py3.py @@ -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 @@ -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 From 6e43e027845876d7c5216f3fec48b9e5a0280fe3 Mon Sep 17 00:00:00 2001 From: Damien Burks Date: Mon, 24 Jan 2022 15:23:27 -0600 Subject: [PATCH 2/3] adding whitespace Signed-off-by: Damien Burks --- fire/inspectutils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fire/inspectutils.py b/fire/inspectutils.py index ca35bc12..1929944a 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -168,6 +168,7 @@ def Py3GetFullArgSpec(fn): if "Optional" in str(annotations[name]) or "Union" in str(annotations[name]): tuple_param1 = get_args(annotations[name])[0].__name__ tuple_param2 = get_args(annotations[name])[1].__name__ + if str(tuple_param2) != "NoneType": annotations[name] = tuple_param1 + ", " + tuple_param2 else: From d916851a8cf74a37ab2ff5c0a09a8058fa60105b Mon Sep 17 00:00:00 2001 From: Damien Burks Date: Wed, 26 Jan 2022 09:22:33 -0600 Subject: [PATCH 3/3] adding update to support union with multiple types --- fire/inspectutils.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fire/inspectutils.py b/fire/inspectutils.py index 1929944a..8834fb7d 100644 --- a/fire/inspectutils.py +++ b/fire/inspectutils.py @@ -166,13 +166,7 @@ def Py3GetFullArgSpec(fn): if param.annotation is not param.empty: annotations[name] = param.annotation if "Optional" in str(annotations[name]) or "Union" in str(annotations[name]): - tuple_param1 = get_args(annotations[name])[0].__name__ - tuple_param2 = get_args(annotations[name])[1].__name__ - - if str(tuple_param2) != "NoneType": - annotations[name] = tuple_param1 + ", " + tuple_param2 - else: - annotations[name] = tuple_param + annotations[name] = ", ".join(x.__name__ for x in get_args(annotations[name])) # pylint: enable=protected-access if not kwdefaults: