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

call_parse defaults to False for any boolean argument, regardless of the actual default specified in the function #533

Open
jpc opened this issue Aug 10, 2023 · 1 comment

Comments

@jpc
Copy link

jpc commented Aug 10, 2023

Example:

from fastcore.script import anno_parser
def test_fun(toggle:bool=True):
    print(toggle)
test_fun()
print(anno_parser(test_fun).parse_args([]))

Prints:

True
Namespace(toggle=False, pdb=False, xtra=None)

What I would expect

True
Namespace(toggle=True, pdb=False, xtra=None)

In this example I think I would prefer the command line parameter to be named "--no-toggle" and the default to be True if the parameter was not passed. There is a store_false annotation but I don't think it can solve this problem alone (I would have to rename the argument to no_toggle and deal with the consequences in my code).

This is caused by this line https://github.com/fastai/fastcore/blob/master/fastcore/script.py#L41 always overriding the default value provided by the function definition in case of boolean arguments.

I hope we could fix this without breaking backwards compatibility. Current code cannot rely on the arg:bool=True to do anything sensible so hopefully everybody avoided using this configuration in existing codebases.

@jph00
Copy link
Member

jph00 commented Apr 26, 2024

Yeah I've gotten confused by this too -- feel free to do a PR with a proposed approach if you like (and please at-mention me).

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

2 participants