📝 Update optional CLI argument section in tutorial with Annotated#983
📝 Update optional CLI argument section in tutorial with Annotated#983tiangolo merged 8 commits intofastapi:masterfrom
Annotated#983Conversation
To match the example, description is updated
svlandeg
left a comment
There was a problem hiding this comment.
Thanks for the PR! The text has indeed gotten a bit out of date as the example code now uses Annotated.
I've rewritten the text again, because we shouldn't focus on the Optional part of the type annotation, as that is not what is making the CLI argument optional 🙃 We need to focus the reader on the fact that there is a default value; whether that is None or not and whether or not the type is Optional[X] is irrelevant. We could also have had
name: Annotated[str, typer.Argument()] = "Rick"
for example. This is sufficiently explained in various parts of the documentation so doesn't need repeating here, but we just need to make sure to avoid confusion with the rephrasing.
Anyway - thanks again for spotting this!
|
📝 Docs preview for commit 26c7b41 at: https://e150a561.typertiangolo.pages.dev Modified Pages |
|
📝 Docs preview for commit 1e96b74 at: https://349df2d6.typertiangolo.pages.dev Modified Pages |
|
📝 Docs preview for commit 844c01a at: https://483c8040.typertiangolo.pages.dev Modified Pages |
|
📝 Docs preview for commit aea1d6d at: https://8b344b2d.typertiangolo.pages.dev Modified Pages |
svlandeg
left a comment
There was a problem hiding this comment.
I've gone ahead and edited this PR further, and I chose to use a default argument "World" in this part of the docs instead of None, to more clearly separate the meaning of "an optional argument" from the type Optional. This meant changing tutorial002 and simplifying it - I think this should make the section more clear.
I'll leave the final review with Tiangolo.
Annotated
|
📝 Docs preview for commit 22ef02d at: https://5e55ac00.typertiangolo.pages.dev Modified Pages |
|
📝 Docs preview for commit 8aa7852 at: https://5541c4c3.typertiangolo.pages.dev Modified Pages |
To match the example, description is updated