You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 EndpointChoices object instead of localhost.
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 None. This is why returning value.value worked instead...because instead of returning the value of the Enum that @app.command already checked, the callback is returning the entire object.
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 None....even as an error it should return the Enum object or raise an error.
Describe the bug
When adding a callback to a
typer.Option
of typeEnum
the value is not passed back to the app command.To Reproduce
Fairly easy to reproduce
main.py
with:Expected behavior
I would expect the option argument to be present in the scope of the app command.
Screenshots
Environment
The text was updated successfully, but these errors were encountered: