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

Confusing behavior on typos when keyword args are reinterpreted as positional arguments #109

Closed
jtratner opened this issue Jan 3, 2018 · 1 comment

Comments

@jtratner
Copy link
Contributor

jtratner commented Jan 3, 2018

Let's say I have some function like this:

def myfunction(arg1, arg2, run_encoding):
     print(arg1, arg2, run_encoding)

fire.Fire()

If I accidentally misspell the run_encoding argument, I get behavior that can be really confusing to debug (e.g., if that's a relative file path, you suddenly get a --mypath=1 directory):

›› python fire_example.py myfunction --arg1=a --arg2=b --run-encoding=5
('a', 'b', 5)
›› python fire_example.py myfunction --arg1=a --arg2=b --runencoding=5                                                                                                           
('a', 'b', '--runencoding=5')

I assume this happens because fire fills in all the keyword args and then assumes you specify positional arguments after them?

What I wish happened instead is that, unless explicitly quoted, any argument starting with -- would be treated as a keyword arg, so you'd see:

1. Initial component
2. Accessed property "myfunction"
3. ('The function received no value for the required argument:', 'run_encoding')

Type:        function
String form: <function myfunction at 0x110138cf8>
File:        /Users/jtratner/fire_example.py
Line:        3

Usage:       fire_example.py myfunction ARG1 ARG2 RUN_ENCODING
             fire_example.py myfunction --arg1 ARG1 --arg2 ARG2 --run-encoding RUN_ENCODING

This is related to the issue in #25, in that if positional arguments were not allowed after keyword arguments, you wouldn't end up with the ambiguity, but I can see how that's less "shell like".

@jtratner
Copy link
Contributor Author

jtratner commented Jan 3, 2018

Oops - this was resolved by #99 - nvm

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

1 participant