Skip to content

Commit 2f265f2

Browse files
📝 Remove documentation pages that reference using Click directly (#1538)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 40430e1 commit 2f265f2

37 files changed

+26
-790
lines changed

docs/features.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ Then it extends those ideas with features and bug fixes. For example, **Typer**
7171

7272
///
7373

74-
## The power of Click
75-
76-
<a href="https://click.palletsprojects.com" class="external-link" target="_blank">Click</a> is one of the most popular tools for building CLIs in Python.
77-
78-
**Typer** is based on it, so you get all its benefits.
79-
80-
But you can write simpler code with the benefits of modern Python.
81-
8274
## Tested
8375

8476
* 100% <abbr title="The amount of code that is automatically tested">test coverage</abbr>.

docs/reference/context.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Context
22

3-
When you create a Typer application it uses Click underneath.
4-
And every Click application has a special object called a [`Context`](https://click.palletsprojects.com/en/stable/api/#click.Context) that is normally hidden.
5-
But you can access the context by declaring a function parameter of type `typer.Context`.
3+
Every app has a special internal object that keeps track of state relevant to the script's execution.
4+
For some advanced use-cases, you may want to access it directly.
5+
This can be done by declaring a function parameter of type `typer.Context`.
6+
7+
Similarly, you can also declare a function parameter with type `typer.CallbackParam` in case a callback could be used
8+
by several CLI parameters, and you need to figure out which one it was.
69

7-
The same way you can access the context by declaring a function parameter with its value,
8-
you can declare another function parameter with type `typer.CallbackParam` to get the specific Click [`Parameter`](https://click.palletsprojects.com/en/stable/api/#click.Parameter) object.
910

1011
```python
1112
from typing import Annotated

docs/tutorial/arguments/envvar.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,3 @@ Hello Mr. Wednesday
116116
```
117117

118118
</div>
119-
120-
/// note | Technical Details
121-
122-
In Click applications the env vars are hidden by default. 🙈
123-
124-
In **Typer** these env vars are shown by default. 👀
125-
126-
///

docs/tutorial/arguments/help.md

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ Options:
112112

113113
</div>
114114

115-
/// note | Technical Details
116-
117-
In Click applications the default values are hidden by default. 🙈
118-
119-
In **Typer** these default values are shown by default. 👀
120-
121-
///
122-
123115
## Custom default string
124116

125117
You can use the same `show_default` to pass a custom string (instead of a `bool`) to customize the default value to be shown in the help text:
@@ -266,28 +258,10 @@ But it won't show up in the main help text under the `Arguments` section.
266258

267259
///
268260

269-
### Help text for *CLI arguments* in Click
270-
271-
Click itself doesn't support adding help for *CLI arguments*, and it doesn't generate help for them as in the "`Arguments:`" sections in the examples above.
272-
273-
Not supporting `help` in *CLI arguments* is an intentional <a href="https://click.palletsprojects.com/en/7.x/documentation/#documenting-arguments" class="external-link" target="_blank">design decision in Click</a>:
274-
275-
> This is to follow the general convention of Unix tools of using arguments for only the most necessary things, and to document them in the command help text by referring to them by name.
261+
### Help text for *CLI arguments*
276262

277-
So, in Click applications, you are expected to write all the documentation for *CLI arguments* by hand in the <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.
278-
279-
---
280-
281-
Nevertheless, **Typer supports `help` for *CLI arguments***. ✨ 🤷‍♂
282-
283-
**Typer** doesn't follow that convention and instead supports `help` to make it easier to have consistent help texts with a consistent format for your CLI programs. 🎨
263+
**Typer supports `help` for *CLI arguments*** to make it easier to have consistent help texts with a consistent format for your CLI programs. 🎨
284264

285265
This is also to help you create CLI programs that are ✨ awesome ✨ *by default*. With very little code.
286266

287-
If you want to keep Click's convention in a **Typer** app, you can do it with the `hidden` parameter as described above.
288-
289-
/// note | Technical Details
290-
291-
To support `help` in *CLI arguments* **Typer** does a lot of internal work in its own sub-classes of Click's internal classes.
292-
293-
///
267+
If you don't want the CLI Argument to be shown in help outputs, you can set the `hidden` parameter to `True`.

docs/tutorial/commands/callback.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,3 @@ Creating user: Camila
159159
```
160160

161161
</div>
162-
163-
## Click Group
164-
165-
If you come from Click, this **Typer** callback is the equivalent of the function in a <a href="https://click.palletsprojects.com/en/7.x/quickstart/#nesting-commands" class="external-link" target="_blank">Click Group</a>.
166-
167-
For example:
168-
169-
```Python
170-
import click
171-
172-
@click.group()
173-
def cli():
174-
pass
175-
```
176-
177-
The original function `cli` would be the equivalent of a Typer callback.
178-
179-
/// note | Technical Details
180-
181-
When using Click, it converts that `cli` variable to a Click `Group` object. And then the original function no longer exists in that variable.
182-
183-
**Typer** doesn't do that, the callback function is not modified, only registered in the `typer.Typer` app. This is intentional, it's part of **Typer**'s design, to allow having editor auto completion and type checks.
184-
185-
///

docs/tutorial/commands/context.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using the Context
22

3-
When you create a **Typer** application it uses Click underneath. And every Click application has a special object called a <a href="https://click.palletsprojects.com/en/8.1.x/commands/#nested-handling-and-contexts" class="external-link" target="_blank">"Context"</a> that is normally hidden.
3+
When you create a **Typer** application it always has a special, hidden object underneath called the "Context".
44

55
But you can access the context by declaring a function parameter of type `typer.Context`.
66

@@ -99,8 +99,6 @@ Creating user: Camila
9999

100100
You can pass configurations for the context when creating a command or callback.
101101

102-
To read more about the available configurations check the docs for <a href="https://click.palletsprojects.com/en/7.x/api/#context" class="external-link" target="_blank">Click's `Context`</a>.
103-
104102
For example, you could keep additional *CLI parameters* not declared in your CLI program with `ignore_unknown_options` and `allow_extra_args`.
105103

106104
Then you can access those extra raw *CLI parameters* as a `list` of `str` in `ctx.args`:

docs/tutorial/commands/index.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,10 @@ Commands:
162162

163163
</div>
164164

165-
## Click Group
166-
167-
If you come from Click, a `typer.Typer` app with subcommands is more or less the equivalent of a <a href="https://click.palletsprojects.com/en/7.x/quickstart/#nesting-commands" class="external-link" target="_blank">Click Group</a>.
168-
169-
/// note | Technical Details
170-
171-
A `typer.Typer` app is *not* a Click Group, but it provides the equivalent functionality. And it creates a Click Group when calling it.
172-
173-
It is not directly a Group because **Typer** doesn't modify the functions in your code to convert them to another type of object, it only registers them.
174-
175-
///
176-
177165
## Decorator Technical Details
178166

179167
When you use `@app.command()` the function under the decorator is registered in the **Typer** application and is then used later by the application.
180168

181169
But Typer doesn't modify that function itself, the function is left as is.
182170

183171
That means that if your function is simple enough that you could create it without using `typer.Option()` or `typer.Argument()`, you could use the same function for a **Typer** application and a **FastAPI** application putting both decorators on top, or similar tricks.
184-
185-
/// note | Click Technical Details
186-
187-
This behavior is a design difference with Click.
188-
189-
In Click, when you add a `@click.command()` decorator it actually modifies the function underneath and replaces it with an object.
190-
191-
///

docs/tutorial/exceptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This code is broken because you can't sum a string and a number (`name + 3`).
1616

1717
**Typer** will automatically use Rich to automatically show you nicely printed errors.
1818

19-
It will **omit** all the parts of the traceback (the chain of things that called your function) that come from the internal parts in Typer and Click.
19+
It will **omit** all the parts of the traceback (the chain of things that called your function) that come from the internal parts in Typer.
2020

2121
So, the error you see will be **much clearer** and simpler, to help you detect the problem in your code quickly:
2222

@@ -112,7 +112,7 @@ But you should only enable it if you're not dealing with delicate information.
112112

113113
## Disable Short Output
114114

115-
If you want to show the full exception, including the parts in Typer and Click, you can use the parameter `pretty_exceptions_short=False`:
115+
If you want to show the full exception, including the internal parts in Typer, you can use the parameter `pretty_exceptions_short=False`:
116116

117117
{* docs_src/exceptions/tutorial003_py39.py hl[3] *}
118118

docs/tutorial/multiple-values/options-with-multiple-values.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ coins = user[1]
4848
is_wizard = user[2]
4949
```
5050

51-
/// tip
52-
53-
Notice that the default is a tuple with `(None, None, None)`.
54-
55-
You cannot simply use `None` here as the default because <a href="https://github.com/pallets/click/issues/472" class="external-link" target="_blank">Click doesn't support it</a>.
56-
57-
///
58-
5951
## Check it
6052

6153
Now let's see how this works in the terminal:

docs/tutorial/options-autocompletion.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ So, in the end, we return a `list` of `tuples` of `str`:
124124

125125
If you want to have help text for each item, make sure each item in the list is a `tuple`. Not a `list`.
126126

127-
Click checks specifically for a `tuple` when extracting the help text.
128-
129-
So in the end, the return will be a `list` (or other iterable) of `tuples` of 2 `str`.
127+
In the end, the return will be a `list` (or other iterable) of `tuples` of 2 `str`.
130128

131129
///
132130

@@ -157,7 +155,7 @@ Sebastian -- The type hints guy.
157155

158156
Instead of creating and returning a list with values (`str` or `tuple`), we can use `yield` with each value that we want in the completion.
159157

160-
That way our function will be a <a href="https://docs.python.org/3.8/glossary.html#index-19" class="external-link" target="_blank">generator</a> that **Typer** (actually Click) can iterate:
158+
That way our function will be a <a href="https://docs.python.org/3.8/glossary.html#index-19" class="external-link" target="_blank">generator</a> that **Typer** can iterate:
161159

162160
{* docs_src/options_autocompletion/tutorial005_an_py39.py hl[12:15] *}
163161

@@ -214,7 +212,7 @@ Hello Sebastian
214212

215213
And the same way as before, we want to provide **completion** for those names. But we don't want to provide the **same names** for completion if they were already given in previous parameters.
216214

217-
For that, we will access and use the "Context". When you create a **Typer** application it uses Click underneath. And every Click application has a special object called a <a href="https://click.palletsprojects.com/en/7.x/commands/#nested-handling-and-contexts" class="external-link" target="_blank">"Context"</a> that is normally hidden.
215+
For that, we will access and use the "Context". Every Typer application has a special object called a "Context" that is normally hidden.
218216

219217
But you can access the context by declaring a function parameter of type `typer.Context`.
220218

@@ -308,7 +306,7 @@ We get all the *CLI parameters* as a raw `list` of `str` by declaring a paramete
308306

309307
/// tip
310308

311-
Here we name the list of all the raw *CLI parameters* `args` because that's the convention with Click.
309+
Here we name the list of all the raw *CLI parameters* `args` because that's the usual convention.
312310

313311
But it doesn't contain only *CLI arguments*, it has everything, including *CLI options* and values, as a raw `list` of `str`.
314312

@@ -384,13 +382,3 @@ You can declare function parameters of these types:
384382
* `list[str]`: for the raw *CLI parameters*.
385383

386384
It doesn't matter how you name them, in which order, or which ones of the 3 options you declare. It will all "**just work**" ✨
387-
388-
## Comparison to Click functionality
389-
390-
Note that Click 7 had a similar [`autocompletion` function](https://click.palletsprojects.com/en/7.x/bashcomplete/), but it worked slightly differently.
391-
392-
It required the callback function to take exactly the 3 arguments `ctx`, `args` and `incomplete` in that exact order, instead of matching them dynamically based on types, as Typer does.
393-
394-
Since Click 8, this functionality has been replaced by [`shell_complete`](https://click.palletsprojects.com/en/8.1.x/api/#click.ParamType.shell_complete), which still depends on the exact order of arguments for the callback function.
395-
396-
However, Typer continues to use the `autocompletion` functionality as described on this page.

0 commit comments

Comments
 (0)