[BUG] callback with type Enum passes None back to the app command #1758
Replies: 2 comments
-
|
Just had the idea to return the value of the def models_callback(value: EndpointChoices):
typer.echo(f"Validating param: {value}, {type(value)}")
return value.valueWhich gives me the result I was expecting raise Exception(type(endpoint))
Exception: <enum 'EndpointChoices'>I'm not sure if this is the expected behavior, though. |
Beta Was this translation helpful? Give feedback.
-
|
Looks like what's happening is that at some point during the callback return, the Enum convertor is being called but it passes in the entire Enum object instead of just the value. In this case, it's passing in the Here is the Enum being passed in the @app.command and returning the expected value: Here is the Enum being returned from the callback into the @app.command. Notice the difference in that it's no longer "localhost" being passed, but "EndpointChoices.localhost" as a string, therefore failing the rest of the function and returning The docs here indicated this is expected behavior, since your callback should receive the same annotation of the main function! However, I think it's counter-intuitive to not handle that case and return |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
When adding a callback to a
typer.Optionof typeEnumthe value is not passed back to the app command.To Reproduce
Fairly easy to reproduce
main.pywith:Expected behavior
I would expect the option argument to be present in the scope of the app command.
Screenshots
Environment
Beta Was this translation helpful? Give feedback.
All reactions