Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jaklan opened this issue Sep 30, 2020 · 4 comments · Fixed by #664
Closed

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

jaklan opened this issue Sep 30, 2020 · 4 comments · Fixed by #664
Labels
bug Something isn't working

Comments

@jaklan
Copy link

jaklan commented Sep 30, 2020

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
@jaklan jaklan added the bug Something isn't working label Sep 30, 2020
@jaywonchung
Copy link

I encountered the same problem as well. Did you find a workaround?

@svlandeg
Copy link
Member

Confirmed that this still seems like an issue, though the output on the current version of Typer v0.9.0 is [], not () (which is still not the expected None)

@svlandeg
Copy link
Member

cf. also #410 for a more extensive example.

@svlandeg
Copy link
Member

PR to fix this issue: #664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants