Default value of False
cast to 'False'
and is thus True
#942
-
First Check
Commit to Help
Example Codeimport typer
def main(do_bad_thing=False):
if do_bad_thing:
raise NotImplementedError
__name__ == '__main__' and typer.run(main) DescriptionWhen running a script without type annotations, but a default boolean value, I sort-of expected the type to be inferred from the default. That's how autocommand works. If the default value is a boolean and no type annotation is given, the type is inferred to be Obviously, this unexpected behavior can be fixed by always supplying type annotations, but since the issue happens silently, it's a bit of a foot gun. Better would be to either use the default value to infer that the type is a bool or warn or raise an Exception if the default value is a bool but no type annotation was given. It's unlikely if the user is supplying a default value of I note also that this behavior differs from how This issue came up in jaraco.develop, where after migrating to Typer in jaraco/jaraco.develop#21, I ran the update-projects script, but it failed when Operating SystemmacOS Operating System Detailsn/a Typer Version0.12.4 Python Version3.13.0rc1 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You should specify the type:
Then it works as expected |
Beta Was this translation helpful? Give feedback.
You should specify the type:
Then it works as expected