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

Optional type args are mistyped in help #508

Open
impredicative opened this issue Apr 19, 2024 · 4 comments · May be fixed by #513
Open

Optional type args are mistyped in help #508

impredicative opened this issue Apr 19, 2024 · 4 comments · May be fixed by #513
Labels

Comments

@impredicative
Copy link

Type annotations that use typing.Optional are incorrectly documented when showing help.

Example 1

from typing import Optional

import fire

def main(arg: Optional[str] = 'something'):
    """Do something with arg."""


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

The corresponding help output is:

INFO: Showing help with the command 'firetest.py -- --help'.

NAME
    firetest.py - Do something with arg.

SYNOPSIS
    firetest.py <flags>

DESCRIPTION
    Do something with arg.

FLAGS
    -a, --arg=ARG
        Type: Optional
        Default: 'something'

Here, Type: Optional is totally incorrect. It should be Optional[str]. My use of str is just an example and it can be anything.

Example 2

from typing import Optional

import fire


def main(arg: Optional[str] = None):
    """Do something with arg."""


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

The corresponding help output is:

INFO: Showing help with the command 'firetest.py -- --help'.

NAME
    firetest.py - Do something with arg.

SYNOPSIS
    firetest.py <flags>

DESCRIPTION
    Do something with arg.

FLAGS
    -a, --arg=ARG
        Type: Optional[Optional]
        Default: None

Here, Type: Optional[Optional] is even more incorrect. It should be Optional[str]. My use of str is just an example and it can be anything.

@dbieber dbieber added the bug label Apr 30, 2024
@dbieber
Copy link
Member

dbieber commented Apr 30, 2024

Thanks for reporting this. Looks like a bug to me. Next steps are to add a test case and identify and resolve the issue.

@Jemeljanov
Copy link

Hi @dbieber,

I submitted pr #513 to solve this bug and added tests, please let me know your opinion.

@Jemeljanov
Copy link

Hi @dbieber,

Updated pr #513 to work with the typing package, waiting for your review on the last commit.

@impredicative
Copy link
Author

impredicative commented Jul 24, 2024

Given that fire is seemingly dead and this bug really harms the displayed help, I figure it's wise to move away from fire. Any decent LLM, e.g. gpt-4o, can replace the use of fire in a module with a different package, e.g. click.

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