Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@jpc

Description

@jpc

Example:

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

Prints:

TrueNamespace(toggle=False, pdb=False, xtra=None)

What I would expect

TrueNamespace(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 astore_false annotation but I don't think it can solve this problem alone (I would have to rename the argument tono_toggle and deal with the consequences in my code).

This is caused by this linehttps://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 thearg:bool=True to do anything sensible so hopefully everybody avoided using this configuration in existing codebases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp