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

arg parsing truncates at hash #338

Open
mgdelmonte opened this issue May 4, 2021 · 4 comments · May be fixed by #406
Open

arg parsing truncates at hash #338

mgdelmonte opened this issue May 4, 2021 · 4 comments · May be fixed by #406
Labels

Comments

@mgdelmonte
Copy link

Fire's arg parser truncates strings with hashes (#) in them. Simple test:

test.py:

import fire
def test(a): print(a, type(a))
fire.Fire(test)
> python test.py hi#there
hi <class 'str'>
> python test.py "hi#there"
hi <class 'str'>

If this is by design, it doesn't appear to be documented anywhere.

@dbieber
Copy link
Member

dbieber commented Jun 7, 2021

This is an unintended side-effect of our reliance on the python ast when parsing inputs:

def _LiteralEval(value):

As a workaround for now, you can add an extra layer of quotes.
python test.py '"hi#there"'

I agree we should improve this behavior.

@dbieber dbieber added the bug label Jun 7, 2021
@sidshrivastav
Copy link

sidshrivastav commented Jun 23, 2022

@dbieber hey can we json.dumps the value in _LiteralEval, then we don't have to give parameter in this manner, '"hi#there"'

@dbieber
Copy link
Member

dbieber commented Jun 23, 2022

I don't think that will work, unfortunately. If the input is "1", json.dumps will produce '"1"' which will get parsed as a string, whereas an int is desired.

@sidshrivastav
Copy link

Ok, let me check how we can use AST with preserving comments.

@xrzqx xrzqx linked a pull request Sep 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants