Skip to content

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

Closed
@melsabagh

Description

@melsabagh

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, ''))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions