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

Cannot parse list of strings containing is #481

Open
rentruewang opened this issue Jan 27, 2024 · 5 comments
Open

Cannot parse list of strings containing is #481

rentruewang opened this issue Jan 27, 2024 · 5 comments
Labels

Comments

@rentruewang
Copy link

rentruewang commented Jan 27, 2024

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.

@dbieber
Copy link
Member

dbieber commented Feb 24, 2024

Good catch. As a workaround for the moment, put quotes around "is".

python example.py --hello '[this,"is",nice]'
['this', 'is', 'nice']

@dbieber dbieber added the bug label Feb 24, 2024
@DavidKatz-il
Copy link

This behavior comes from the ast.parse here

@ajitg25
Copy link

ajitg25 commented Apr 18, 2024

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.

@rentruewang
Copy link
Author

rentruewang commented Apr 18, 2024

@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.

@ajitg25
Copy link

ajitg25 commented May 1, 2024

Please assign this issue to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants