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

Less than helpful help text for Optional[int] argument #329

Open
genos opened this issue Mar 30, 2021 · 1 comment
Open

Less than helpful help text for Optional[int] argument #329

genos opened this issue Mar 30, 2021 · 1 comment

Comments

@genos
Copy link

genos commented Mar 30, 2021

Hi friends! Thanks as always for this amazing library; it's really made building CLIs in Python a breeze.

One thing I've noticed recently: when Fire-ing a function with an argument of type Optional[int], the help text for that argument has a bit of extraneous noise and gets cut off in such a way that we never see the int portion. Exempli gratia:

Environment

~/tmp ∃ python3 -m venv env
~/tmp ∃ source env/bin/activate
(env) ~/tmp ∃ pip install -U -q pip fire
(env) ~/tmp ∃ python --version
Python 3.8.7
(env) ~/tmp ∃ pip freeze
fire==0.4.0
six==1.15.0
termcolor==1.1.0

Script

#!/usr/bin/env python
from typing import Optional
from fire import Fire

def main(n: Optional[int] = None):
    n = 5 if n is None else n
    print(f"You chose {n}.")

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

Running

When I run ./test.py --help, I receive the following help message:

NAME
    test.py

SYNOPSIS
    test.py <flags>

FLAGS
    --n=N
        Type: Optional[typing.Unio...
        Default: None

Desiderata

Perhaps it's happening because Optional[T] is equivalent to Union[T, None], but I find the type annotation's abbreviationOptional[typing.Unio...] in the help text a little wanting; ideally I'd prefer something like Optional[int] there. Granted, if this weren't a contrived, simplified example, I'd include a docstring that described the optional integer argument and not expect fire to take care of everything for me! But it'd be nice if we could see the type parameter inside that Optional.

Thanks again!

@damienjburks
Copy link

damienjburks commented Jan 15, 2022

I'd like to do this one! I'll raise a PR for this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants