-
-
Notifications
You must be signed in to change notification settings - Fork 805
📝 Update docs to use Typer() more prominently
#1418
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
base: master
Are you sure you want to change the base?
Conversation
| {* docs_src/arguments/optional/tutorial000.py hl[4] *} | ||
|
|
||
| {* docs_src/arguments/optional/tutorial001_an.py hl[5] *} | ||
| Or, using an explicit `Typer()` instance creation: | ||
|
|
||
| {* docs_src/arguments/optional/tutorial001_an.py hl[8] *} |
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.
Here, I've created a new tutorial file (docs_src/arguments/optional/tutorial000.py) to better show the difference with the more simplistic docs_src/first_steps/tutorial002.py. The next version then (docs_src/arguments/optional/tutorial001_an.py) introduces both Annotated as well as Typer().
| {* docs_src/arguments/optional/tutorial003.py hl[7] *} | ||
|
|
||
| And the same way, you can make it optional by passing a different `default` value, for example `None`: | ||
| And the same way, you can make it optional by passing a different `default` value, for example `"World"`: |
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.
Here, and in the lines below, I've had to make extra edits, because this section had become out-of-date on master after PR #983. Basically in PR 983 we updated tutorial002 to have the default value "World" instead of None, and we updated the explanation around L112 but didn't notice that this same example was being used here at the end of the page at L220 and beyond.
|
|
||
| Here I'll use **CLI application** or **program** to refer to the program you are building in Python with Typer, and **command** to refer to one of these "subcommands" of your program. | ||
|
|
||
| ## Explicit application |
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 bit is moved almost verbatim to typer-instance.md, with some minor edits to ensure correct flow.
| @@ -0,0 +1,116 @@ | |||
| ## Explicit application | |||
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.
Now, the title of this page is "Typer instance" - we should decide whether this is what we want, or something else.
docs/tutorial/exceptions.md
Outdated
| <font color="#F92672">│</font> 7 <font color="#F92672">│</font> | ||
| <font color="#F92672">│</font> 8 <font color="#66D9EF">if</font> <font color="#F92672">__name__</font> == <font color="#F4BF75">"__main__"</font>: <font color="#F92672">│</font> | ||
| <font color="#F92672">│</font> 5 <font color="#F92672">│</font> | ||
| <font color="#F92672">│</font> 6 <font color="#FF00FF">@app</font>.command() <font color="#F92672">│</font> |
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.
TODO: outline this correctly 🙈
In an attempt to be minimal/clear, the docs have mostly been using
typer.run. However for proper applications, we recommend to useTyper()directly, which unlocks much more options. As such, we're updating the docs here. This has the added advantage that it's easier to experiment with given tutorial examples without first having to adjust them to useTyper().I know reviewing this is horrible. I've taken the time to go through every edit carefully (0% vibe coding ;-)). Mostly, this meant updating the tutorial examples and then updating the highlighted lines in the documentation markdown files. There were some special cases, that I'll highlight as review comments.