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

  1. tevinch commented on Nov 12, 2026

    @tevinch

    For this parameter, you can set Fire's parser explicitly in 0.7.1:

    import fire
    from fire import decorators
    
    @decorators.SetParseFns(arg=str)
    def main(arg: str):
        print(f"Hello! {type(arg)} {arg}")
    
    if __name__ == "__main__":
        fire.Fire(main)

    Then both python tp.py 1.10 and python tp.py --arg=1.10 print:

    Hello! <class 'str'> 1.10
    

    SetParseFns(arg=str) applies to this parameter for positional and named arguments; other parameters retain their normal parsing. The public decorator configures the parser independently of the annotation.

    The guide's argument-parsing section explains the value-based inference and quoting. Ordinary shell quotes disappear before Fire receives the argument, so '1.10' alone does not force a string. Converting to str after parsing cannot recover the lost zero.

    Runnable examples and subprocess checks cover the original command and preserving a string beside a numeric parameter, using Fire 0.7.1.

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