python-fire
python-fire copied to clipboard
Cannot parse list of strings containing `is`
Reproduce as such:
# example.py
import fire
def main(hello: list[str]):
print(hello)
fire.Fire(main)
python example.py --hello '[this,is,nice]'
This would yield the unexpected output where in the main function hello would be a string "[this,is,nice]". The correct behavior should be ["this", "is", "nice"]
This doesn't happen with non-keywords.
Good catch. As a workaround for the moment, put quotes around "is".
python example.py --hello '[this,"is",nice]'
['this', 'is', 'nice']
This behavior comes from the ast.parse here
I am trying to understand the issue here @dbieber. When I am trying to get the elements from the list for example
import fire
def main(hello: list[str]):
for i in hello:
print(i)
fire.Fire(main)
The output is:
[
t
h
i
s
,
i
s
,
n
i
c
e
]
isnt it should be like:
this
is
nice
I want to fix this issue so it will be helpful is you could explain a bit.
@ajitg25
My guess is because fire would try to convert "2.5" in the command line to 2.5 by calling python's built in eval during parsing. Therefore, keywords not in quotes would cause SyntaxError probably for eval. This is a good behavior for numbers like 2.5, not so much for "is". That is why I raised the issue.
Please assign this issue to me.