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

Defaults for kwonly arguments don't show in help #410

Closed
melsabagh opened this issue Oct 20, 2022 · 2 comments · Fixed by #414
Closed

Defaults for kwonly arguments don't show in help #410

melsabagh opened this issue Oct 20, 2022 · 2 comments · Fixed by #414
Labels

Comments

@melsabagh
Copy link

melsabagh commented Oct 20, 2022

Fire (v0.4.0, master) does not seem to show default values for keyword-only arguments. Consider the following example:

#!/usr/bin/env python3

import fire


def foo(*, bar=True):
    print(bar)


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

Save it as foo.py and run python3 foo.py --help.

Expected Output:

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

NAME
    foo.py

SYNOPSIS
    foo.py <flags>

FLAGS
    --bar=BAR
        Default: True

Actual Output:

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

NAME
    foo.py

SYNOPSIS
    foo.py <flags>

FLAGS
    --bar=BAR

Looks like a one line change could fix this: change the return statement here

return ''
to:

    return repr(spec.kwonlydefaults.get(flag, ''))
@amrutharajashekar
Copy link

Hi I would like to work on this issue.

Thanks!

@dbieber dbieber added the bug label Nov 28, 2022
@dbieber
Copy link
Member

dbieber commented Nov 28, 2022

return repr(spec.kwonlydefaults.get(flag, ''))

Thanks for identifying the fix. Quick note - repr('') doesn't evaluate to '', so that one-liner is quite right, but it gets the idea across. Let's include this improvement in the next release 👍

dbieber added a commit that referenced this issue Nov 28, 2022
Fixes #410

* Shows default values for kwonly arguments in help text
* Adds test verifying that default values are shown for kwonly args
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