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

[feature request] support multiple dialects for boolean parameters #461

Open
iRyoka opened this issue Aug 31, 2023 · 3 comments
Open

[feature request] support multiple dialects for boolean parameters #461

iRyoka opened this issue Aug 31, 2023 · 3 comments

Comments

@iRyoka
Copy link

iRyoka commented Aug 31, 2023

Consider the following code:

import fire

def a(flag: bool):
   if flag: 
      print("hooray!")
   else:
      print("Wanna see a flag :(")

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

Now, the following options work as expected (print 'hooray!'):
python a.py --flag
python a.py --flag=True
python a.py --flag=true

However, in order to disable flag explicity the only working option is:
python a.py --flag=False
and the seemingly rational version
python a.py --flag=false
result in 'hooray' being printed as flag is parsed as a string 'false' which then casts to boolean True.

My request:
support 0, 'false' and 'no' as valid boolean arguments that all cast to False. Make this behavior optional. One way to do this is by adding a custom type to lable such flags with.

@pranshugupta01
Copy link

Hi , can i work on this issue by adding a custom function for detecting different boolean types.

@dbieber
Copy link
Member

dbieber commented Dec 12, 2023

Another thing that works is --noflag

@dbieber
Copy link
Member

dbieber commented Dec 12, 2023

Implementing this request would have to come as part of a larger change: using type annotations to infer types and parse arguments accordingly; this isn't planned at this time.

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

3 participants