Skip to content

[BUG] Optional multi-value option returns empty tuple instead of None #170

Closed
@jaklan

Description

@jaklan

Describe the bug

Optional multi-value option returns empty tuple instead of None.

To Reproduce

  • Create a file main.py with:
from typing import List, Optional

import typer

app = typer.Typer()


@app.command()
def main(jobs: Optional[List[str]] = None): # or `typer.Option(None)`
    print(jobs)


if __name__ == "__main__":
    app()
  • Call it with:
python main.py
  • It outputs:
()
  • But I expected it to output:
None

Expected behavior

The expected behavior for an empty parameter annotated with Optional and = None is both documented and commonly known - it should be just None. And that's also how it works in Typer, but for some reason - only for single-value options.

Environment

  • OS: macOS
  • Typer version: 0.3.2
  • Python version: 3.8.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions