Skip to content

Optional and required flags are swapped in the "Usage" message #315

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

Closed
Mirandatz opened this issue Feb 4, 2021 · 8 comments · Fixed by #316
Closed

Optional and required flags are swapped in the "Usage" message #315

Mirandatz opened this issue Feb 4, 2021 · 8 comments · Fixed by #316
Labels

Comments

@Mirandatz
Copy link

Running python script.py command

import fire


class Example:

    def command(self, *, arg1: bool, arg2: bool = True, arg3: bool = False):
        pass


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

Prints

ERROR: Missing required flags: {'arg1'}
Usage: download.py command <flags>
  optional flags:        --arg1
  required flags:        --arg2 | --arg3

The "ERROR" message correctly points that arg1 is required, but the "Usage" message is swapping required and optional arguments.

@dbieber dbieber added the bug label Feb 4, 2021
@dbieber
Copy link
Collaborator

dbieber commented Feb 4, 2021

Thanks for reporting the issue!

@xavierfigueroav
Copy link
Contributor

I would like to take this issue!

@dbieber
Copy link
Collaborator

dbieber commented Feb 4, 2021

Excellent, thanks xavierfigueroav. Let me know if you need any pointers to get started.

@xavierfigueroav
Copy link
Contributor

xavierfigueroav commented Feb 4, 2021

I think I got it, it was very simple. I guess I have to write tests for the change. If so, I need pointers on how to simulate the call python script.py command. I think that the following component is the most suitable for this case:

class MixedDefaults(object):
def ten(self):
return 10
def sum(self, alpha=0, beta=0):
return alpha + 2 * beta
def identity(self, alpha, beta='0'):
return alpha, beta

But, I don't know how to simulate the call to identity from it. Just component = tc.MixedDefaults() or component = tc.MixedDefaults().identity doesn't seem to reproduce the case.

@xavierfigueroav
Copy link
Contributor

It seems that the bare * actually matters 😅. I need something like

class Example:
    def command(self, *, arg1, arg2=True, arg3=False):
        pass

So, should I add a function like that to the MixedDefaults component or create a new component?

@xavierfigueroav
Copy link
Contributor

Well, I opened #316. If any changes are needed, please, let me know.

@dzieciou
Copy link

dzieciou commented Apr 7, 2022

What's the progress on that? 1 year passed and still a problem

@dbieber
Copy link
Collaborator

dbieber commented Apr 7, 2022

No new developments. Thanks for the ping.

The PR looks good -- should be able to merge it in my next fire working session (haven't had one recently, hence the issue going stale).

dbieber pushed a commit that referenced this issue Apr 16, 2022
* Change the _KeywordOnlyArguments filtering condition
* Add test case for usage output of function with mixed defaults

Signed-off-by: Xavier Figueroa <[email protected]>
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.

4 participants