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

Provide strict mode #226

Open
MaxG87 opened this issue Feb 24, 2020 · 2 comments
Open

Provide strict mode #226

MaxG87 opened this issue Feb 24, 2020 · 2 comments

Comments

@MaxG87
Copy link

MaxG87 commented Feb 24, 2020

You already mentioned to plan to add a strict mode to python-fire in #221 and #222. I would highly appreciate this, so I am opening a new issue for this.

The problem with CLI facing function is that MyPy cannot help here. The type of the input arguments depends on how python-fire (or other CLI parsers) parse the arguments. Thus type hinting cannot spot errors. I for myself had strings were I expected a number (e.g. by passing in "02" instead of "2") or lists where I expected strings (erroneous trailing comma "foobar,"). There is no way to catch this except for explicitly checking for it.

I am currently experimenting with [[https://pypi.org/project/dpcontracts/|dpcontracts]] and https://github.com/RussBaz/enforce to prevent CLI induced errors. However, strict mode would make things much easier here.

One requirement for me would be that I can enable strict mode from within the script. Having to pass `--strict`` all the time would not prevent errors due to wrong usage.

I would be very glad to see this comming.

@8enmann
Copy link

8enmann commented Aug 5, 2020

I would love this! Without it I am going back to argparse

@tonio-m
Copy link

tonio-m commented Aug 4, 2022

This feature would be nice, but if you're trying to call a function from command line using Fire, you can always validate the inputs of the function by putting a decorator called @beartype on it.

It is provided by this lib:
https://github.com/beartype/beartype

>>> @beartype
... def spirit_bear(kermode: str, gitgaata: (str, int)) -> tuple:
...     return (kermode, gitgaata, "Moksgm'ol", 'Ursus americanus kermodei')
>>> spirit_bear(0xdeadbeef, 'People of the Cane')
AssertionError: parameter kermode=0xdeadbeef not of <class "str">

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

No branches or pull requests

4 participants