Skip to content

String hinted arguments passed numerical values should not be coerced #733

Open

Description

@bjester

Observed behavior

If a callable command function defines an argument with a string hint, e.g. arg: str, and a value of 1.10 is passed to it, then it receives an argument of type float with value 1.1 which has different meaning than the passed value.

This is particularly troublesome when dealing with versions since 1.1 is much different than 1.10.

Expected behavior

Fire should not coerce the value to a type different than the type hint, regardless of its format.

Reproduction

Code

# tp.py
import fire


def main(arg: str):
    print(f"Hello! {type(arg)} {arg}")


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

Execution

$ python tp.py 1.10
Hello! <class 'float'> 1.1

or

$ python tp.py '1.10'
Hello! <class 'float'> 1.1

Metadata

fire version v0.7.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions