From 534b66a8219ac1178cb18bf53de8a552556ab564 Mon Sep 17 00:00:00 2001 From: abdrzq84 Date: Wed, 21 Sep 2022 04:26:07 +0700 Subject: [PATCH 1/3] Fix arg parsing truncates at hash --- fire/parser.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fire/parser.py b/fire/parser.py index 404e18e7..22726540 100644 --- a/fire/parser.py +++ b/fire/parser.py @@ -66,7 +66,6 @@ def DefaultParseValue(value): Returns: The parsed value, of the type determined most appropriate. """ - # Note: _LiteralEval will treat '#' as the start of a comment. try: return _LiteralEval(value) except (SyntaxError, ValueError): @@ -105,8 +104,12 @@ def _LiteralEval(value): child[index] = _Replacement(subchild) elif isinstance(child, ast.Name): - replacement = _Replacement(child) - node.__setattr__(field, replacement) + if isinstance(value, str) and not isinstance(value, int): + replacement = ast.Str(value) + node.__setattr__(field, replacement) + else: + replacement = _Replacement(child) + node.__setattr__(field, replacement) # ast.literal_eval supports the following types: # strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None From f233ce7b39e5b49e387498270e72948753eda9a7 Mon Sep 17 00:00:00 2001 From: abdrzq84 Date: Wed, 21 Sep 2022 09:04:05 +0700 Subject: [PATCH 2/3] Provide compatibility with python2.7 --- example.py | 8 ++++++++ fire/parser.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 example.py diff --git a/example.py b/example.py new file mode 100644 index 00000000..c227a0ec --- /dev/null +++ b/example.py @@ -0,0 +1,8 @@ +# import fire +# import sys + +# sys.argv.append('(1,2)') +# fire.Fire(lambda obj: type(obj).__name__) + +import fire +fire.Fire(lambda obj: type(obj).__name__) \ No newline at end of file diff --git a/fire/parser.py b/fire/parser.py index 22726540..7ab18aa5 100644 --- a/fire/parser.py +++ b/fire/parser.py @@ -104,7 +104,7 @@ def _LiteralEval(value): child[index] = _Replacement(subchild) elif isinstance(child, ast.Name): - if isinstance(value, str) and not isinstance(value, int): + if isinstance(type(value), str) and not isinstance(type(value), int): replacement = ast.Str(value) node.__setattr__(field, replacement) else: From cb68efc25f9a97cbfe9931a38fd4d54efe1e39da Mon Sep 17 00:00:00 2001 From: Abdul Razzaq <66063339+xrzqx@users.noreply.github.com> Date: Wed, 21 Sep 2022 09:43:20 +0700 Subject: [PATCH 3/3] Delete my unused file --- example.py | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 example.py diff --git a/example.py b/example.py deleted file mode 100644 index c227a0ec..00000000 --- a/example.py +++ /dev/null @@ -1,8 +0,0 @@ -# import fire -# import sys - -# sys.argv.append('(1,2)') -# fire.Fire(lambda obj: type(obj).__name__) - -import fire -fire.Fire(lambda obj: type(obj).__name__) \ No newline at end of file