✨ Support typing.Literal to define a set of predefined choices#429
✨ Support typing.Literal to define a set of predefined choices#429tiangolo merged 45 commits intofastapi:masterfrom
typing.Literal to define a set of predefined choices#429Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Any updates on merging this? @tiangolo |
|
Upvote for this PR, as using Literal is more succinct then using enum. |
atmartinez
left a comment
There was a problem hiding this comment.
There is the possibility to import Literal from typing_extensions to allow this to work for 3.6 (since Typer still says it support it despite being EOL) and 3.7 as well. This may be a moot consideration soon though since 3.7 goes EOL in June 2023 as well if there are any plans to drop unsupported Python versions at some point.
This may require adding a specific dependency for typing_extensions, but it's currently being installed by another dep regardless from some of the CI runs I checked for 3.6+ 4.1-4.4 depending on the Python version.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Update:
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
I was really hoping this got merged for the latest release 2 weeks ago 👀 |
This comment was marked as outdated.
This comment was marked as outdated.
typing.Literal to define a set of predefined choices
|
📝 Docs preview for commit d876108 at: https://b44fab2b.typertiangolo.pages.dev Modified Pages |
Copied PR #174 from someone who deleted their account because I think it's worth reopening this PR and adding this functionality to typer.
Original PR message: