Skip to content

📝 Update optional CLI argument section in tutorial with Annotated#983

Merged
tiangolo merged 8 commits intofastapi:masterfrom
gkeuccsr:patch-1
Feb 27, 2025
Merged

📝 Update optional CLI argument section in tutorial with Annotated#983
tiangolo merged 8 commits intofastapi:masterfrom
gkeuccsr:patch-1

Conversation

@gkeuccsr
Copy link
Copy Markdown
Contributor

@gkeuccsr gkeuccsr commented Sep 9, 2024

To match the example, description is updated

To match the example, description is updated
@github-actions github-actions Bot added the docs Improvements or additions to documentation label Sep 9, 2024
@svlandeg svlandeg self-assigned this Sep 10, 2024
Copy link
Copy Markdown
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread docs/tutorial/arguments/optional.md Outdated
Comment thread docs/tutorial/arguments/optional.md Outdated
@svlandeg svlandeg removed their assignment Sep 10, 2024
@svlandeg svlandeg changed the title Fix outdated optional *CLI argument* section in tutorial 📝 Fix outdated optional *CLI argument* section in tutorial Sep 10, 2024
@svlandeg svlandeg self-assigned this Oct 25, 2024
@svlandeg svlandeg marked this pull request as draft January 8, 2025 13:38
Copy link
Copy Markdown
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@svlandeg svlandeg marked this pull request as ready for review January 8, 2025 14:57
@svlandeg svlandeg removed their assignment Jan 8, 2025
Comment thread docs/tutorial/arguments/optional.md Outdated
@tiangolo tiangolo changed the title 📝 Fix outdated optional *CLI argument* section in tutorial 📝 Update optional CLI argument section in tutorial with Annotated Feb 27, 2025
Copy link
Copy Markdown
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you @gkeuccsr! 🚀 ☕

And thanks for the help @svlandeg! 🙇

@tiangolo tiangolo enabled auto-merge (squash) February 27, 2025 18:39
@tiangolo tiangolo merged commit 563e63e into fastapi:master Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants