-
-
Notifications
You must be signed in to change notification settings - Fork 833
Open
Labels
Description
Describe the bug
When adding a callback to a typer.Option of type Enum the value is not passed back to the app command.
To Reproduce
Fairly easy to reproduce
- Create a file
main.pywith:
import typer
from enum import Enum
app = typer.Typer()
class EndpointChoices(str, Enum):
localhost = "localhost"
staging = "staging"
production = "production"
def models_callback(value: EndpointChoices):
typer.echo(f"Validating param: {value}, {type(value)}")
return value
@app.command()
def models(endpoint: EndpointChoices = typer.Option(
..., case_sensitive=False, callback=models_callback
)
):
"""List available models"""
raise Exception(endpoint)
if __name__ == "__main__":
app()- Call it with:
python main.py --endpoint localhost- It outputs:
raise Exception(endpoint)
Exception: None
- But I expected it to output:
localhost, <enum 'EndpointChoices'>
Expected behavior
I would expect the option argument to be present in the scope of the app command.
Screenshots
Environment
- OS: Ubuntu 20.04
- Python 3.8.5
- Typer Version 0.3.2
frederikaalund, twyair, bhirsz and YuriiMotov