TypeError - <argument/option name> is defined twice #834
-
First Check
Commit to Help
Example CodeIn main file:
import typer
app = typer.Typer()
app.add_typer(solr_cli.solr_app, name="solr")
... # main commands In import typer
solr_app = typer.Typer()
@solr_app.command("download")
def download(
version: Annotated[
str,
typer.Option(
"latest",
"--version",
help="The version of the Solr KG to download (latest, dev, or a specific version)",
),
] = "latest",
overwrite: Annotated[
bool,
typer.Option(
False,
"--overwrite",
help="Overwrite the existing Solr KG if it exists",
),
] = False,
):
"""Download the Monarch Solr KG."""
ensure_solr(version, overwrite) # util that uses pystow to download a file if missing
raise typer.Exit()
... # other commands, none of which have version as an argument DescriptionI have a primary CLI file, and a secondary But when I run any command at all, I get:
This was apparently happening before the release of typer v0.12, when we were using 0.7 with typer-cli separate, but I can't pin down when it started happening or why Operating SystemLinux Operating System DetailsNo LSB modules are available. Typer Version0.12.3 Python Version3.11.9 Additional ContextRelated code with issue can be seen in Some additional notes:
It's possible this issue is with click itself and not typer, but given the first note above, I'm suspicious it has to do with how typer is constructing things to pass to click Full stack trace:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Whenever I use |
Beta Was this translation helpful? Give feedback.
-
So I ended up here due to getting the same error. My issue was, however, completely different. With the code input_folder: str = typer.Option(
None,
"--input-folder",
"in",
help="Folder where ALL the reference data is present"
), I get the error: If I change the declaration |
Beta Was this translation helpful? Give feedback.
-
Try removing the “default” values from typer.Option(). It should help. @solr_app.command("download")
def download(
version: Annotated[
str,
typer.Option(
"--version",
help="The version of the Solr KG to download (latest, dev, or a specific version)",
),
] = "latest",
overwrite: Annotated[
bool,
typer.Option(
"--overwrite",
help="Overwrite the existing Solr KG if it exists",
),
] = False,
): |
Beta Was this translation helpful? Give feedback.
Try removing the “default” values from typer.Option(). It should help.