Consider the following little program:
import click
@click.command()
#@click.option("--arg") #(1)
@click.option("--arg", default=17) #(2)
def command(arg=19):
print(arg, type(arg))
if __name__=='__main__':
command()
Here, if using declaration (1), passing an argument with --arg will result in the passing of a string argument. On the other hand, declaration (2) overrides the default and forces the programmer to repeat defaults.
It would seem to be nicer behavior if @click.option used reflection to get the default value from keyword arguments, removing the need for duplication of the default and avoiding potential type inconsistencies.
(Perhaps to avoid backwards incompatibility where people rely on the odd current behavior, the fix could use a slight variant, say, @click.opt. When used with default=, it would just behave as the current options.)
import click
@click.command()
@click.opt("--arg", help="defaults to '19' of type 'int'")
def command(arg=19):
print(arg, type(arg))
if __name__=='__main__':
command()
Consider the following little program:
Here, if using declaration (1), passing an argument with
--argwill result in the passing of a string argument. On the other hand, declaration (2) overrides the default and forces the programmer to repeat defaults.It would seem to be nicer behavior if
@click.optionused reflection to get the default value from keyword arguments, removing the need for duplication of the default and avoiding potential type inconsistencies.(Perhaps to avoid backwards incompatibility where people rely on the odd current behavior, the fix could use a slight variant, say,
@click.opt. When used withdefault=, it would just behave as the current options.)