typer icon indicating copy to clipboard operation
typer copied to clipboard

[BUG] Type hint for show_default of typer.Option is incorrect

Open gadostal-swordfish opened this issue 3 years ago • 1 comments

Describe the bug

For typer.Argument, the type hint for show_default is this: show_default: Union[bool, str] = True, for typer.Option, the type hint is this: show_default: bool = True,

For an argument, I can override the text that accompanies the default value to be something like "working directory". This permits me to do document generation including usage blocks that don't have paths from the build system in them.

For an option, I can do the same but I need to suppress type check. The functionality works regardless of the type hints.

To Reproduce

Run mypy against this code:

def docker_build(context_path: Path = typer.Argument(Path.cwd(), exists=True,
                                                     show_default=working_directory_label,
                                                     resolve_path=True),
                           dockerfile: Path = typer.Option(Path.cwd() / "Dockerfile", "--file", "-f", exists=True, dir_okay=False,
                                                                              show_default="Dockerfile in working directory", resolve_path =True)):
    pass

Environment

  • OS: Centos7
  • Typer Version 0.3.1
  • Python version: 3.6.8

gadostal-swordfish avatar Aug 31 '20 02:08 gadostal-swordfish

I'm also running into this issue.

355 fixes this

Dymstro avatar Mar 08 '22 13:03 Dymstro

Since it seems like the other PR might be slowed down by introducing other functionality, I created a PR solely to address this issue.

plannigan avatar Nov 15 '22 03:11 plannigan