First Check
Commit to Help
Example Codeimport typer
from typing import Annotated
app = typer.Typer()
@app.command()
def run(name: Annotated[str, typer.Option("--name")]):
print(f"name={name!r}")
if __name__ == "__main__":
app()DescriptionRestating the example code above: repro.py: import typer
from typing import Annotated
app = typer.Typer()
@app.command()
def run(name: Annotated[str, typer.Option("--name")]):
print(f"name={name!r}")pip install "typer[all]==0.12.0" "click==8.3.2"
python repro.py --name helloExpected: Actual: To confirm the option is being registered as a flag, introspect it: repro-inspect.py import typer
from typing import Annotated
app = typer.Typer()
@app.command()
def run(name: Annotated[str, typer.Option("--name")]):
pass
cli = typer.main.get_command(app)
for param in cli.params:
if param.name == "name":
print(f"type={param.type}, is_flag={param.is_flag}")python repro-inspect.py --name helloOutput with Click 8.3.x:
Before Click 8.3.0, Click 8.3.0 introduced an # click/core.py ~line 2723
flag_value: t.Any = UNSET,
# ~line 2777
if is_flag is None:
if flag_value is not UNSET: # None is not UNSET → True for every Typer option
is_flag = TrueBecause Typer always passes Possible FixPerhaps typer should not forward Operating SystemmacOS Operating System DetailsNo response Typer Version0.12.0 Python VersionPython 3.13.0 Additional ContextNo response |
Replies: 2 comments 1 reply
|
This looks like the old Typer/Click compatibility edge rather than expected The first thing I would do is reproduce on current Typer. If you are stuck on Typer |
|
My apologies: I should have checked a newer version first! I was able to upgrade my project to 0.24.2 and can confirm this issue is no longer present. Thanks! |
This looks like the old Typer/Click compatibility edge rather than expected
Optionbehavior. Typer has moved a long way since0.12.0; the current package metadata requires Click>= 8.2.1, and the current code path no longer appears to pass the staleflag_value=Noneshape that Click 8.3 exposes here.The first thing I would do is reproduce on current Typer. If you are stuck on Typer
0.12.0, pin Click below8.3for that environment. If upgrading is possible, upgrade Typer instead of working around it in every option declaration.