python-fire
python-fire copied to clipboard
arg parsing truncates at hash
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.
This is an unintended side-effect of our reliance on the python ast when parsing inputs: https://github.com/google/python-fire/blob/c1266d0dbb2114514fcf8be62044344b5a51c733/fire/parser.py#L77
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 hey can we json.dumps the value in _LiteralEval, then we don't have to give parameter in this manner, '"hi#there"'
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.
Ok, let me check how we can use AST with preserving comments.