-
-
Notifications
You must be signed in to change notification settings - Fork 674
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
✨ Add support for PEP-593 Annotated
for specifying options and arguments
#584
Conversation
📝 Docs preview for commit 4c8ec06 at: https://64485c5170ff0b41deceb08d--typertiangolo.netlify.app |
📝 Docs preview for commit af327f1 at: https://64485e9ce8a02045f093fbe4--typertiangolo.netlify.app |
📝 Docs preview for commit e4b0857 at: https://64486108fbfcff49634a32af--typertiangolo.netlify.app |
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
e4b0857
to
452fc6f
Compare
📝 Docs preview for commit 452fc6f at: https://644863863678c34b7b416e31--typertiangolo.netlify.app |
📝 Docs preview for commit 4c0d058 at: https://644867cee1091d4cc2a37c70--typertiangolo.netlify.app |
📝 Docs preview for commit 83cce68 at: https://64508bba537334776a49a9a1--typertiangolo.netlify.app |
📝 Docs preview for commit ba312c5 at: https://64508dfd6a3f5b73af9d5eec--typertiangolo.netlify.app |
# When used as a default, `Option` takes a default value and option names | ||
# as positional arguments: | ||
# `Option(some_value, "--some-argument", "-s")` | ||
# When used in `Annotated` (ie, what this is handling), `Option` just takes | ||
# option names as positional arguments: | ||
# `Option("--some-argument", "-s")` | ||
# In this case, the `default` attribute of `parameter_info` is actually | ||
# meant to be the first item of `param_decls`. | ||
if ( | ||
isinstance(parameter_info, OptionInfo) | ||
and parameter_info.default is not ... | ||
): | ||
parameter_info.param_decls = ( | ||
cast(str, parameter_info.default), | ||
*(parameter_info.param_decls or ()), | ||
) | ||
parameter_info.default = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very clever! 😎 🚀
Great job @ryangalamb! 👏 🍰 I tweaked a couple of things, tests, and examples. And I added all the new annotated examples to the docs. I also updated the docs to introduce the new This will be available in Typer |
Implements #184
In addition to the tests/implementation, this PR also adds/updates
docs_src
files for all the tutorial files that can useAnnotated
.Each
tutorial00N.py
file withAnnotated
is copied totutorial00N_an.py
and an_an.py
version of its test is created intests/test_tutorial
. (This is modeled after the convention used in FastAPI.)Adding the tutorial files results in a pretty massive PR, so let me know if you'd prefer those in a separate PR.
I've tested this on
Please let me know if there's anything you'd like me to change/address 🙏