-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
[FEATURE] Use Python 3.9's Annotated[T, *metadata]
(PEP 593) to describe parameters
#184
Comments
Annotated[T, m...]
(PEP 593) to describe parametersAnnotated[T, *metadata]
(PEP 593) to describe parameters
Annotated[T, *metadata]
(PEP 593) to describe parametersAnnotated[T, *metadata]
(PEP 593) to describe parameters
It would be very useful. Cant wait implementation. |
+1 for implementation. Can I help in any way? Is there any option to plug-in typer with this functionality? |
Similar PR in FastAPI repo hasn't been merged yet, it's possible this is waiting for Pydantic-Core to be released more broadly (I know Sebastian and Samuel Colvin talk 😋) to fix this at an even more fundamental level. |
…ments (#584) * ✨ Add support for PEP-593 `Annotated` for specifying options and arguments Implements #184 * Revert things I did to get a 3.6 virtualenv 😅 A lot of the dev dependency packages weren't installable on 3.6, so I had to remove them from the pyproject.toml. This commit adds them back * Fix mypy/lint errors * Skip coverage on test lines that shouldn't execute * Missed a spot * ♻️ Tweak examples and tests with Annotated, add extra examples and tests * 🔥 Remove Pydantic-specific logic from _typing.py * 📝 Update docs to use new Annotated examples * 📝 Add docs introducing Annotated and previous versions * 🔧 Add commented out MkDocs config for highlighting docs examples * ✅ Fix tests for Click 7 --------- Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Hello there! This was implemented in #584, here are the new docs: https://typer.tiangolo.com/tutorial/arguments/optional/#an-alternative-cli-argument-declaration, it's available in Typer 0.9.0, just released 🚀 |
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
Is your feature request related to a problem
Not really, the current solution is already great.
The solution you would like
Add an alternative syntax to describe optional parameters, PEP 593's
Annotated[T, *metadata]
. Now, strictly speaking of syntax, it's not much better, but it's built into python, and thus might help integration with IDEs in the future.Help for optional parameters could be provided as the second argument of
Annotated
:is equivalent to
As a bonus, there's no need to do a weird
thing: type = Argument(..., help="description")
when you want to specify help without giving a default value, just dothing: Annotated[type, "description"]
Also, it might be a little easier to implement since there's no messing with default values.
An
Annotated
parameter to the function will resolve to:Argument
if it has no default valueOption
elseDescribe alternatives you've considered
Making it always resolve to
Argument
or always toOption
, or use something likeAnnotated[type, "description", form=Argument
for arguments andAnnotated[type, "description", form=Option]
for options. I'm not sure about this.tbh this is debatable, but I figured I'd throw the idea out there, since this shiny new python 3.9 feature could be useful to Typer, as it seems that the use case described in the PEP is fitting:
— PEP 593, python.org
The text was updated successfully, but these errors were encountered: