Positional-only argument instead of typer.Argument #1584
Replies: 6 comments
|
Well, you can do something like that: import typer
app = typer.Typer()
@app.command()
def main(
arg: str, opt: int = 1
):
print(arg)
print(opt)
if __name__ == "__main__":
app()
def main(arg: str, arg2: str = 2, /, opt: int, opt2: int = 1, ): passThis however is invalid Python syntax, because you cannot have non-default parameters after default parameters, here: non-default An obvious drawback is also that I understand that the |
|
This would probably be useful, no? def main(arg: str, arg2: int = 2, /, opt: int = 1): passRequired options are rarely a good idea. |
|
Regarding Python 3.8: It would of course be possible to still use def main(arg: str, arg2: str = 2, /, opt: int = typer.Option(...), opt2: int = 1): passThe combination of optional argument and required option is bad CLI design, so making that awkward isn’t a bad tradeoff. |
|
Hello, I'm also interested by this proposal. I find the current way to define default values for arguments (and making them optional) require too much boilerplate for something that's already in the language with the positional-only method arguments. I'm happy to make a PR implementing this. Is this something maintainers would accept? |
|
I think this will not simplify things a lot since:
At the same time it brings additional maintenance burden. See also more broad similar idea: #331 |
|
Maintenance burden, really? I’m a maintainer, and a better user-facing API is always worth adding like 2 new tests for me. But since cyclopts exists, I’m no longer as invested in Typer anyway. |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem
Using positional-only arguments is already a way to signal “this argument has no name”.
It’s shorter and natural to use
The solution you would like
would work like
Describe alternatives you've considered
Continue using
typer.ArgumentAll reactions