Skip to content

Unexpected parsing behaviour for --date=2018-12-09 vs. --date=2018-12-10 #102

@martinvirtel

Description

@martinvirtel

Anything that can be interpreted as an arithmetics expression will be magically "calculated" by fire. This is very practical. But it bit me because I wanted to parse dates from command line parameters using fire, see below.

Suggestion: accept type hints as a way to prevent this. A parameter with type hint "str" shoud not be "calculated".

Test code:


def test(string: str=None) :
    print(string)

if __name__=="__main__" :
    fire.Fire(test)

Will give you:

> python ./test-parsing.py --string=2010-10-10
1990    # not interpreted as a string, but as 2010 minus 10 minus 10

> python ./test-parsing.py --string=2010-10-09
2010-10-09

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions