Skip to content
Discussion options

You must be logged in to vote

This is a disadvantage of old-style approach when you specify `` as default value.
To avoid this, use Annotated approach:

Instead of

def cmd1(number: int = typer.Option(1, help="An integer for cmd1")):

use

def cmd1(number: Annotated[int, typer.Option(help="An integer for cmd1")] = 1):

Full example:

from typing import Annotated
import typer

app = typer.Typer()


@app.command()
def cmd1(number: Annotated[int, typer.Option(help="An integer for cmd1")] = 1):
    typer.echo(f"Running cmd1 with number: {number}")
    cmd2()

@app.command()
def cmd2(number: Annotated[int, typer.Option(help="An integer for cmd2")] = 2):
    typer.echo(f"Running cmd2 with number: {number}")


if __name__ == "__ma…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants