Skip to content
Myr

🔥 Remove support for Python 3.6 (#758)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parent 2b29e98 · Browse files · 37 files+180 added−246 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

37 files+180 added−246 removed

  • tests:+9 added−50 removed
  • other:+171 added−196 removed

37 files+180 added−246 removed

modified:.github/workflows/test.yml+2 added-7 removed
modified:docs/tutorial/arguments/default.md+4 added-4 removed
4 unmodified lines
5## An optional *CLI argument* with a default67We can also use `typer.Argument()` to make a *CLI argument* have a default value other than `None`:89=== "Python 3.6+"9=== "Python 3.7+"1011 ```Python hl_lines="5"12 {!> ../docs_src/arguments/default/tutorial001_an.py!}13 ```1415=== "Python 3.6+ non-Annotated"15=== "Python 3.7+ non-Annotated"1617 !!! tip18 Prefer to use the `Annotated` version if possible.19
39 unmodified lines
59## Dynamic default value6061And we can even make the default value be dynamically generated by passing a function as the `default_factory` argument:6263=== "Python 3.6+"63=== "Python 3.7+"6465 ```Python hl_lines="7-8 11"66 {!> ../docs_src/arguments/default/tutorial002_an.py!}67 ```6869=== "Python 3.6+ non-Annotated"69=== "Python 3.7+ non-Annotated"7071 !!! tip72 Prefer to use the `Annotated` version if possible.73
47 unmodified lines
modified:docs/tutorial/arguments/envvar.md+6 added-6 removed
1You can also configure a *CLI argument* to read a value from an environment variable if it is not provided in the command line as a *CLI argument*.23To do that, use the `envvar` parameter for `typer.Argument()`:45=== "Python 3.6+"5=== "Python 3.7+"67 ```Python hl_lines="5"8 {!> ../docs_src/arguments/envvar/tutorial001_an.py!}9 ```1011=== "Python 3.6+ non-Annotated"11=== "Python 3.7+ non-Annotated"1213 !!! tip14 Prefer to use the `Annotated` version if possible.15
43 unmodified lines
59## Multiple environment variables6061You are not restricted to a single environment variable, you can declare a list of environment variables that could be used to get a value if it was not passed in the command line:6263=== "Python 3.6+"63=== "Python 3.7+"6465 ```Python hl_lines="6"66 {!> ../docs_src/arguments/envvar/tutorial002_an.py!}67 ```6869=== "Python 3.6+ non-Annotated"69=== "Python 3.7+ non-Annotated"7071 !!! tip72 Prefer to use the `Annotated` version if possible.73
33 unmodified lines
107## Hide an env var from the help text108109By default, environment variables used will be shown in the help text, but you can disable them with `show_envvar=False`:110111=== "Python 3.6+"111=== "Python 3.7+"112113 ```Python hl_lines="7"114 {!> ../docs_src/arguments/envvar/tutorial003_an.py!}115 ```116117=== "Python 3.6+ non-Annotated"117=== "Python 3.7+ non-Annotated"118119 !!! tip120 Prefer to use the `Annotated` version if possible.121
33 unmodified lines
modified:docs/tutorial/arguments/help.md+16 added-16 removed
10 unmodified lines
11## Add a `help` text for a *CLI argument*1213You can use the `help` parameter to add a help text for a *CLI argument*:1415=== "Python 3.6+"15=== "Python 3.7+"1617 ```Python hl_lines="5"18 {!> ../docs_src/arguments/help/tutorial001_an.py!}19 ```2021=== "Python 3.6+ non-Annotated"21=== "Python 3.7+ non-Annotated"2223 !!! tip24 Prefer to use the `Annotated` version if possible.25
23 unmodified lines
49## Combine help text and docstrings5051And of course, you can also combine that `help` with the <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>:5253=== "Python 3.6+"53=== "Python 3.7+"5455 ```Python hl_lines="5-8"56 {!> ../docs_src/arguments/help/tutorial002_an.py!}57 ```5859=== "Python 3.6+ non-Annotated"59=== "Python 3.7+ non-Annotated"6061 !!! tip62 Prefer to use the `Annotated` version if possible.63
25 unmodified lines
89## Help with defaults9091If you have a *CLI argument* with a default value, like `"World"`:9293=== "Python 3.6+"93=== "Python 3.7+"9495 ```Python hl_lines="5"96 {!> ../docs_src/arguments/help/tutorial003_an.py!}97 ```9899=== "Python 3.6+ non-Annotated"99=== "Python 3.7+ non-Annotated"100101 !!! tip102 Prefer to use the `Annotated` version if possible.103
23 unmodified lines
127</div>128129But you can disable that if you want to, with `show_default=False`:130131=== "Python 3.6+"131=== "Python 3.7+"132133 ```Python hl_lines="7"134 {!> ../docs_src/arguments/help/tutorial004_an.py!}135 ```136137=== "Python 3.6+ non-Annotated"137=== "Python 3.7+ non-Annotated"138139 !!! tip140 Prefer to use the `Annotated` version if possible.141
30 unmodified lines
172## Custom default string173174You 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:175176=== "Python 3.6+"176=== "Python 3.7+"177178 ```Python hl_lines="9"179 {!> ../docs_src/arguments/help/tutorial005_an.py!}180 ```181182=== "Python 3.6+ non-Annotated"182=== "Python 3.7+ non-Annotated"183184 !!! tip185 Prefer to use the `Annotated` version if possible.186
43 unmodified lines
230But you can customize it with the `metavar` parameter for `typer.Argument()`.231232For example, let's say you don't want to have the default of `NAME`, you want to have `username`, in lowercase, and you really want ✨ emojis ✨ everywhere:233234=== "Python 3.6+"234=== "Python 3.7+"235236 ```Python hl_lines="5"237 {!> ../docs_src/arguments/help/tutorial006_an.py!}238 ```239240=== "Python 3.6+ non-Annotated"240=== "Python 3.7+ non-Annotated"241242 !!! tip243 Prefer to use the `Annotated` version if possible.244
24 unmodified lines
269You might want to show the help information for *CLI arguments* in different panels when using the `--help` option.270271If you have installed Rich as described in the docs for [Printing and Colors](../printing.md){.internal-link target=_blank}, you can set the `rich_help_panel` parameter to the name of the panel where you want this *CLI argument* to be shown:272273=== "Python 3.6+"273=== "Python 3.7+"274275 ```Python hl_lines="8 12"276 {!> ../docs_src/arguments/help/tutorial007_an.py!}277 ```278279=== "Python 3.6+ non-Annotated"279=== "Python 3.7+ non-Annotated"280281 !!! tip282 Prefer to use the `Annotated` version if possible.283
41 unmodified lines
325If you want, you can make a *CLI argument* **not** show up in the `Arguments` section in the help text.326327You will probably not want to do this normally, but it's possible:328329=== "Python 3.6+"329=== "Python 3.7+"330331 ```Python hl_lines="5"332 {!> ../docs_src/arguments/help/tutorial008_an.py!}333 ```334335=== "Python 3.6+ non-Annotated"335=== "Python 3.7+ non-Annotated"336337 !!! tip338 Prefer to use the `Annotated` version if possible.339
49 unmodified lines
modified:docs/tutorial/commands/help.md+9 added-9 removed
1The same as before, you can add help for the commands in the docstrings and the *CLI options*.23And the `typer.Typer()` application receives a parameter `help` that you can pass with the main help text for your CLI program:45=== "Python 3.6+"5=== "Python 3.7+"67 ```Python hl_lines="4 9-11 22 26-30 43 47-51 60-62"8 {!> ../docs_src/commands/help/tutorial001_an.py!}9 ```1011=== "Python 3.6+ non-Annotated"11=== "Python 3.7+ non-Annotated"1213 !!! tip14 Prefer to use the `Annotated` version if possible.15
184 unmodified lines
200### Rich Markup201202If you set `rich_markup_mode="rich"` when creating the `typer.Typer()` app, you will be able to use <a href="https://rich.readthedocs.io/en/stable/markup.html" class="external-link" target="_blank">Rich Console Markup</a> in the docstring, and even in the help for the *CLI arguments* and options:203204=== "Python 3.6+"204=== "Python 3.7+"205206 ```Python hl_lines="4 10 14-16 21 24 27"207 {!> ../docs_src/commands/help/tutorial004_an.py!}208 ```209210=== "Python 3.6+ non-Annotated"210=== "Python 3.7+ non-Annotated"211212 !!! tip213 Prefer to use the `Annotated` version if possible.214
61 unmodified lines
276### Rich Markdown277278If you set `rich_markup_mode="markdown"` when creating the `typer.Typer()` app, you will be able to use Markdown in the docstring:279280=== "Python 3.6+"280=== "Python 3.7+"281282 ```Python hl_lines="4 9 12-20 25 27-28"283 {!> ../docs_src/commands/help/tutorial005_an.py!}284 ```285286=== "Python 3.6+ non-Annotated"286=== "Python 3.7+ non-Annotated"287288 !!! tip289 Prefer to use the `Annotated` version if possible.290
71 unmodified lines
362### Help Panels for Commands363364To set the panel for a command you can pass the argument `rich_help_panel` with the name of the panel you want to use:365366=== "Python 3.6+"366=== "Python 3.7+"367368 ```Python hl_lines="22 30 38 46"369 {!> ../docs_src/commands/help/tutorial006.py!}370 ```
36 unmodified lines
407The same way, you can configure the panels for *CLI arguments* and *CLI options* with `rich_help_panel`.408409And of course, in the same application you can also set the `rich_help_panel` for commands.410411=== "Python 3.6+"411=== "Python 3.7+"412413 ```Python hl_lines="15 21 27 37"414 {!> ../docs_src/commands/help/tutorial007_an.py!}415 ```416417=== "Python 3.6+ non-Annotated"417=== "Python 3.7+ non-Annotated"418419 !!! tip420 Prefer to use the `Annotated` version if possible.421
111 unmodified lines
modified:docs/tutorial/commands/options.md+2 added-2 removed
1Commands can also have their own *CLI options*.23In fact, each command can have different *CLI arguments* and *CLI options*:45=== "Python 3.6+"5=== "Python 3.7+"67 ```Python hl_lines="8 14-17 27-29 38"8 {!> ../docs_src/commands/options/tutorial001_an.py!}9 ```1011=== "Python 3.6+ non-Annotated"11=== "Python 3.7+ non-Annotated"1213 !!! tip14 Prefer to use the `Annotated` version if possible.15
92 unmodified lines
modified:docs/tutorial/multiple-values/arguments-with-multiple-values.md+2 added-2 removed
modified:docs/tutorial/multiple-values/multiple-options.md+4 added-4 removed
2 unmodified lines
3For example, let's say you want to accept several users in a single execution.45For this, use the standard Python `typing.List` to declare it as a `list` of `str`:67=== "Python 3.6+"7=== "Python 3.7+"89 ```Python hl_lines="1 7"10 {!> ../docs_src/multiple_values/multiple_options/tutorial001_an.py!}11 ```1213=== "Python 3.6+ non-Annotated"13=== "Python 3.7+ non-Annotated"1415 !!! tip16 Prefer to use the `Annotated` version if possible.17
32 unmodified lines
50## Multiple `float`5152The same way, you can use other types and they will be converted by **Typer** to their declared type:5354=== "Python 3.6+"54=== "Python 3.7+"5556 ```Python hl_lines="7"57 {!> ../docs_src/multiple_values/multiple_options/tutorial002_an.py!}58 ```5960=== "Python 3.6+ non-Annotated"60=== "Python 3.7+ non-Annotated"6162 !!! tip63 Prefer to use the `Annotated` version if possible.64
25 unmodified lines
modified:docs/tutorial/multiple-values/options-with-multiple-values.md+2 added-2 removed
2 unmodified lines
3You can set the number of values and types to anything you want, but it has to be a fixed number of values.45For this, use the standard Python `typing.Tuple`:67=== "Python 3.6+"7=== "Python 3.7+"89 ```Python hl_lines="1 7"10 {!> ../docs_src/multiple_values/options_with_multiple_values/tutorial001_an.py!}11 ```1213=== "Python 3.6+ non-Annotated"13=== "Python 3.7+ non-Annotated"1415 !!! tip16 Prefer to use the `Annotated` version if possible.17
84 unmodified lines
modified:docs/tutorial/options/callback-and-context.md+8 added-8 removed
4 unmodified lines
5## Validate *CLI parameters*67For example, you could do some validation before the rest of the code is executed.89=== "Python 3.6+"9=== "Python 3.7+"1011 ```Python hl_lines="5-8 11"12 {!> ../docs_src/options/callback/tutorial001_an.py!}13 ```1415=== "Python 3.6+ non-Annotated"15=== "Python 3.7+ non-Annotated"1617 !!! tip18 Prefer to use the `Annotated` version if possible.19
84 unmodified lines
104### Breaking completion in a callback105106Let's say that when the callback is running, we want to show a message saying that it's validating the name:107108=== "Python 3.6+"108=== "Python 3.7+"109110 ```Python hl_lines="6"111 {!> ../docs_src/options/callback/tutorial002_an.py!}112 ```113114=== "Python 3.6+ non-Annotated"114=== "Python 3.7+ non-Annotated"115116 !!! tip117 Prefer to use the `Annotated` version if possible.118
33 unmodified lines
152But you can access the context by declaring a function parameter of type `typer.Context`.153154The "context" has some additional data about the current execution of your program:155156=== "Python 3.6+"156=== "Python 3.7+"157158 ```Python hl_lines="5-7"159 {!> ../docs_src/options/callback/tutorial003_an.py!}160 ```161162=== "Python 3.6+ non-Annotated"162=== "Python 3.7+ non-Annotated"163164 !!! tip165 Prefer to use the `Annotated` version if possible.166
30 unmodified lines
197## Using the `CallbackParam` object198199The same way you can access the `typer.Context` by declaring a function parameter with its value, you can declare another function parameter with type `typer.CallbackParam` to get the specific Click `Parameter` object.200201=== "Python 3.6+"201=== "Python 3.7+"202203 ```Python hl_lines="5 8"204 {!> ../docs_src/options/callback/tutorial004_an.py!}205 ```206207=== "Python 3.6+ non-Annotated"207=== "Python 3.7+ non-Annotated"208209 !!! tip210 Prefer to use the `Annotated` version if possible.211
50 unmodified lines
modified:docs/tutorial/options/help.md+8 added-8 removed
1You already saw how to add a help text for *CLI arguments* with the `help` parameter.23Let's now do the same for *CLI options*:45=== "Python 3.6+"5=== "Python 3.7+"67 ```Python hl_lines="7-8"8 {!> ../docs_src/options/help/tutorial001_an.py!}9 ```1011=== "Python 3.6+ non-Annotated"11=== "Python 3.7+ non-Annotated"1213 !!! tip14 Prefer to use the `Annotated` version if possible.15
50 unmodified lines
66The same as with *CLI arguments*, you can put the help for some *CLI options* in different panels to be shown with the `--help` option.6768If you have installed Rich as described in the docs for [Printing and Colors](../printing.md){.internal-link target=_blank}, you can set the `rich_help_panel` parameter to the name of the panel you want for each *CLI option*:6970=== "Python 3.6+"70=== "Python 3.7+"7172 ```Python hl_lines="11 17"73 {!> ../docs_src/options/help/tutorial002_an.py!}74 ```7576=== "Python 3.6+ non-Annotated"76=== "Python 3.7+ non-Annotated"7778 !!! tip79 Prefer to use the `Annotated` version if possible.80
44 unmodified lines
125## Hide default from help126127You can tell Typer to not show the default value in the help text with `show_default=False`:128129=== "Python 3.6+"129=== "Python 3.7+"130131 ```Python hl_lines="5"132 {!> ../docs_src/options/help/tutorial003_an.py!}133 ```134135=== "Python 3.6+ non-Annotated"135=== "Python 3.7+ non-Annotated"136137 !!! tip138 Prefer to use the `Annotated` version if possible.139
32 unmodified lines
172## Custom default string173174You 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:175176=== "Python 3.6+"176=== "Python 3.7+"177178 ```Python hl_lines="7"179 {!> ../docs_src/options/help/tutorial004_an.py!}180 ```181182=== "Python 3.6+ non-Annotated"182=== "Python 3.7+ non-Annotated"183184 !!! tip185 Prefer to use the `Annotated` version if possible.186
26 unmodified lines
modified:docs/tutorial/options/name.md+10 added-10 removed
24 unmodified lines
25Let's say the function parameter name is `user_name` as above, but you want the *CLI option* to be just `--name`.2627You can pass the *CLI option* name that you want to have in the following positional argument passed to `typer.Option()`:2829=== "Python 3.6+"29=== "Python 3.7+"3031 ```Python hl_lines="5"32 {!> ../docs_src/options/name/tutorial001_an.py!}33 ```3435 Here you are passing the string `"--name"` as the first positional argument to `typer.Option()`.3637=== "Python 3.6+ non-Annotated"37=== "Python 3.7+ non-Annotated"3839 !!! tip40 Prefer to use the `Annotated` version if possible.41
151 unmodified lines
193You can overwrite the *CLI option* name to use as in the previous example, but you can also declare extra alternatives, including short names.194195For example, extending the previous example, let's add a *CLI option* short name `-n`:196197=== "Python 3.6+"197=== "Python 3.7+"198199 ```Python hl_lines="5"200 {!> ../docs_src/options/name/tutorial002_an.py!}201 ```202203=== "Python 3.6+ non-Annotated"203=== "Python 3.7+ non-Annotated"204205 !!! tip206 Prefer to use the `Annotated` version if possible.207
29 unmodified lines
237### *CLI option* only short name238239If you only declare a short name like `-n` then that will be the only *CLI option* name. And neither `--name` nor `--user-name` will be available.240241=== "Python 3.6+"241=== "Python 3.7+"242243 ```Python hl_lines="5"244 {!> ../docs_src/options/name/tutorial003_an.py!}245 ```246247=== "Python 3.6+ non-Annotated"247=== "Python 3.7+ non-Annotated"248249 !!! tip250 Prefer to use the `Annotated` version if possible.251
26 unmodified lines
278### *CLI option* short name and default279280Continuing with the example above, as **Typer** allows you to declare a *CLI option* as having only a short name, if you want to have the default long name plus a short name, you have to declare both explicitly:281282=== "Python 3.6+"282=== "Python 3.7+"283284 ```Python hl_lines="5"285 {!> ../docs_src/options/name/tutorial004_an.py!}286 ```287288=== "Python 3.6+ non-Annotated"288=== "Python 3.7+ non-Annotated"289290 !!! tip291 Prefer to use the `Annotated` version if possible.292
32 unmodified lines
325You can create multiple short names and use them together.326327You don't have to do anything special for it to work (apart from declaring those short versions):328329=== "Python 3.6+"329=== "Python 3.7+"330331 ```Python hl_lines="6-7"332 {!> ../docs_src/options/name/tutorial005_an.py!}333 ```334335=== "Python 3.6+ non-Annotated"335=== "Python 3.7+ non-Annotated"336337 !!! tip338 Prefer to use the `Annotated` version if possible.339
36 unmodified lines
modified:docs/tutorial/options/password.md+4 added-4 removed
1Apart from having a prompt, you can make a *CLI option* have a `confirmation_prompt=True`:23=== "Python 3.6+"3=== "Python 3.7+"45 ```Python hl_lines="7"6 {!> ../docs_src/options/password/tutorial001_an.py!}7 ```89=== "Python 3.6+ non-Annotated"9=== "Python 3.7+ non-Annotated"1011 !!! tip12 Prefer to use the `Annotated` version if possible.13
26 unmodified lines
40You can achieve the same using `hide_input=True`.4142And if you combine it with `confirmation_prompt=True` you can easily receive a password with double confirmation:4344=== "Python 3.6+"44=== "Python 3.7+"4546 ```Python hl_lines="8"47 {!> ../docs_src/options/password/tutorial002_an.py!}48 ```4950=== "Python 3.6+ non-Annotated"50=== "Python 3.7+ non-Annotated"5152 !!! tip53 Prefer to use the `Annotated` version if possible.54
21 unmodified lines
modified:docs/tutorial/options/prompt.md+6 added-6 removed
1It's also possible to, instead of just showing an error, ask for the missing value with `prompt=True`:23=== "Python 3.6+"3=== "Python 3.7+"45 ```Python hl_lines="5"6 {!> ../docs_src/options/prompt/tutorial001_an.py!}7 ```89=== "Python 3.6+ non-Annotated"9=== "Python 3.7+ non-Annotated"1011 !!! tip12 Prefer to use the `Annotated` version if possible.13
20 unmodified lines
34## Customize the prompt3536You can also set a custom prompt, passing the string that you want to use instead of just `True`:3738=== "Python 3.6+"38=== "Python 3.7+"3940 ```Python hl_lines="7"41 {!> ../docs_src/options/prompt/tutorial002_an.py!}42 ```4344=== "Python 3.6+ non-Annotated"44=== "Python 3.7+ non-Annotated"4546 !!! tip47 Prefer to use the `Annotated` version if possible.48
24 unmodified lines
73You can do it passing the parameter `confirmation_prompt=True`.7475Let's say it's a CLI app to delete a project:7677=== "Python 3.6+"77=== "Python 3.7+"7879 ```Python hl_lines="6"80 {!> ../docs_src/options/prompt/tutorial003_an.py!}81 ```8283=== "Python 3.6+ non-Annotated"83=== "Python 3.7+ non-Annotated"8485 !!! tip86 Prefer to use the `Annotated` version if possible.87
34 unmodified lines
modified:docs/tutorial/options/required.md+3 added-3 removed
9 unmodified lines
10To make a *CLI option* required, you can put `typer.Option()` inside of `Annotated` and leave the parameter without a default value.1112Let's make `--lastname` a required *CLI option*:1314=== "Python 3.6+"14=== "Python 3.7+"1516 ```Python hl_lines="5"17 {!> ../docs_src/options/required/tutorial001_an.py!}18 ```1920The same way as with `typer.Argument()`, the old style of using the function parameter default value is also supported, in that case you would just not pass anything to the `default` parameter.2122=== "Python 3.6+ non-Annotated"22=== "Python 3.7+ non-Annotated"2324 ```Python hl_lines="4"25 {!> ../docs_src/options/required/tutorial001.py!}26 ```2728Or you can explictily pass `...` to `typer.Option(default=...)`:2930=== "Python 3.6+ non-Annotated"30=== "Python 3.7+ non-Annotated"3132 ```Python hl_lines="4"33 {!> ../docs_src/options/required/tutorial002.py!}34 ```
41 unmodified lines
modified:docs/tutorial/options/version.md+6 added-6 removed
4 unmodified lines
5## First version of `--version`67Let's see a first version of how it could look like:89=== "Python 3.6+"9=== "Python 3.7+"1011 ```Python hl_lines="9-12 17-19"12 {!> ../docs_src/options/version/tutorial001_an.py!}13 ```1415=== "Python 3.6+ non-Annotated"15=== "Python 3.7+ non-Annotated"1617 !!! tip18 Prefer to use the `Annotated` version if possible.19
44 unmodified lines
64## Previous parameters and `is_eager`6566But now let's say that the `--name` *CLI option* that we declared before `--version` is required, and it has a callback that could exit the program:6768=== "Python 3.6+"68=== "Python 3.7+"6970 ```Python hl_lines="15-17 22-24"71 {!> ../docs_src/options/version/tutorial002_an.py!}72 ```7374=== "Python 3.6+ non-Annotated"74=== "Python 3.7+ non-Annotated"7576 !!! tip77 Prefer to use the `Annotated` version if possible.78
28 unmodified lines
107For those cases, we can mark a *CLI parameter* (a *CLI option* or *CLI argument*) with `is_eager=True`.108109That will tell **Typer** (actually Click) that it should process this *CLI parameter* before the others:110111=== "Python 3.6+"111=== "Python 3.7+"112113 ```Python hl_lines="23-26"114 {!> ../docs_src/options/version/tutorial003_an.py!}115 ```116117=== "Python 3.6+ non-Annotated"117=== "Python 3.7+ non-Annotated"118119 !!! tip120 Prefer to use the `Annotated` version if possible.121
16 unmodified lines
modified:docs/tutorial/parameter-types/bool.md+8 added-8 removed
6 unmodified lines
7Let's say that we want a `--force` *CLI option* only, we want to discard `--no-force`.89We can do that by specifying the exact name we want:1011=== "Python 3.6+"11=== "Python 3.7+"1213 ```Python hl_lines="5"14 {!> ../docs_src/parameter_types/bool/tutorial001_an.py!}15 ```1617=== "Python 3.6+ non-Annotated"17=== "Python 3.7+ non-Annotated"1819 !!! tip20 Prefer to use the `Annotated` version if possible.21
46 unmodified lines
68We might want to instead have `--accept` and `--reject`.6970We can do that by passing a single `str` with the 2 names for the `bool` *CLI option* separated by `/`:7172=== "Python 3.6+"72=== "Python 3.7+"7374 ```Python hl_lines="7"75 {!> ../docs_src/parameter_types/bool/tutorial002_an.py!}76 ```7778=== "Python 3.6+ non-Annotated"78=== "Python 3.7+ non-Annotated"7980 !!! tip81 Prefer to use the `Annotated` version if possible.82
39 unmodified lines
122The same way, you can declare short versions of the names for these *CLI options*.123124For example, let's say we want `-f` for `--force` and `-F` for `--no-force`:125126=== "Python 3.6+"126=== "Python 3.7+"127128 ```Python hl_lines="5"129 {!> ../docs_src/parameter_types/bool/tutorial003_an.py!}130 ```131132=== "Python 3.6+ non-Annotated"132=== "Python 3.7+ non-Annotated"133134 !!! tip135 Prefer to use the `Annotated` version if possible.136
34 unmodified lines
171If you want to (although it might not be a good idea), you can declare only *CLI option* names to set the `False` value.172173To do that, use a space and a single `/` and pass the negative name after:174175=== "Python 3.6+"175=== "Python 3.7+"176177 ```Python hl_lines="5"178 {!> ../docs_src/parameter_types/bool/tutorial004_an.py!}179 ```180181=== "Python 3.6+ non-Annotated"181=== "Python 3.7+ non-Annotated"182183 !!! tip184 Prefer to use the `Annotated` version if possible.185
41 unmodified lines
modified:docs/tutorial/parameter-types/custom-types.md+4 added-4 removed
9 unmodified lines
10## Type Parser1112`typer.Argument` and `typer.Option` can create custom parameter types with a `parser` <abbr title="something that can be called like a function">callable</abbr>.1314=== "Python 3.6+"14=== "Python 3.7+"1516 ```Python hl_lines="13-14 18-19"17 {!> ../docs_src/parameter_types/custom_types/tutorial001_an.py!}18 ```1920=== "Python 3.6+ non-Annotated"20=== "Python 3.7+ non-Annotated"2122 !!! tip23 Prefer to use the `Annotated` version if possible.24
6 unmodified lines
31## Click Custom Type3233If you already have a <a href="https://click.palletsprojects.com/en/8.1.x/parameters/#implementing-custom-types" class="external-link" target="_blank">Click Custom Type</a>, you can use it in `typer.Argument()` and `typer.Option()` with the `click_type` parameter.3435=== "Python 3.6+"35=== "Python 3.7+"3637 ```Python hl_lines="14-18 22-25"38 {!> ../docs_src/parameter_types/custom_types/tutorial002_an.py!}39 ```4041=== "Python 3.6+ non-Annotated"41=== "Python 3.7+ non-Annotated"4243 !!! tip44 Prefer to use the `Annotated` version if possible.45
3 unmodified lines
modified:docs/tutorial/parameter-types/datetime.md+2 added-2 removed
56 unmodified lines
57* separated with "`/`"5859...It's a crazy example, but let's say you also needed that strange format:6061=== "Python 3.6+"61=== "Python 3.7+"6263 ```Python hl_lines="11"64 {!> ../docs_src/parameter_types/datetime/tutorial002_an.py!}65 ```6667=== "Python 3.6+ non-Annotated"67=== "Python 3.7+ non-Annotated"6869 !!! tip70 Prefer to use the `Annotated` version if possible.71
24 unmodified lines
modified:docs/tutorial/parameter-types/enum.md+4 added-4 removed
49 unmodified lines
50### Case insensitive Enum choices5152You can make an `Enum` (choice) *CLI parameter* be case-insensitive with the `case_sensitive` parameter:5354=== "Python 3.6+"54=== "Python 3.7+"5556 ```Python hl_lines="15"57 {!> ../docs_src/parameter_types/enum/tutorial002_an.py!}58 ```5960=== "Python 3.6+ non-Annotated"60=== "Python 3.7+ non-Annotated"6162 !!! tip63 Prefer to use the `Annotated` version if possible.64
22 unmodified lines
87### List of Enum values8889A *CLI parameter* can also take a list of `Enum` values:9091=== "Python 3.6+"91=== "Python 3.7+"9293 ```Python hl_lines="14"94 {!> ../docs_src/parameter_types/enum/tutorial003_an.py!}95 ```9697=== "Python 3.6+ non-Annotated"97=== "Python 3.7+ non-Annotated"9899 !!! tip100 Prefer to use the `Annotated` version if possible.101
35 unmodified lines
modified:docs/tutorial/parameter-types/file.md+10 added-10 removed
40 unmodified lines
41```4243You will get all the correct editor support, attributes, methods, etc for the file-like object:`4445=== "Python 3.6+"45=== "Python 3.7+"4647 ```Python hl_lines="5"48 {!> ../docs_src/parameter_types/file/tutorial001_an.py!}49 ```5051=== "Python 3.6+ non-Annotated"51=== "Python 3.7+ non-Annotated"5253 !!! tip54 Prefer to use the `Annotated` version if possible.55
25 unmodified lines
81## `FileTextWrite`8283For writing text, you can use `typer.FileTextWrite`:8485=== "Python 3.6+"85=== "Python 3.7+"8687 ```Python hl_lines="5-6"88 {!> ../docs_src/parameter_types/file/tutorial002_an.py!}89 ```9091=== "Python 3.6+ non-Annotated"91=== "Python 3.7+ non-Annotated"9293 !!! tip94 Prefer to use the `Annotated` version if possible.95
39 unmodified lines
135You will receive `bytes` from it.136137It's useful for reading binary files like images:138139=== "Python 3.6+"139=== "Python 3.7+"140141 ```Python hl_lines="5"142 {!> ../docs_src/parameter_types/file/tutorial003_an.py!}143 ```144145=== "Python 3.6+ non-Annotated"145=== "Python 3.7+ non-Annotated"146147 !!! tip148 Prefer to use the `Annotated` version if possible.149
27 unmodified lines
177Have in mind that you have to pass `bytes` to its `.write()` method, not `str`.178179If you have a `str`, you have to encode it first to get `bytes`.180181=== "Python 3.6+"181=== "Python 3.7+"182183 ```Python hl_lines="5"184 {!> ../docs_src/parameter_types/file/tutorial004_an.py!}185 ```186187=== "Python 3.6+ non-Annotated"187=== "Python 3.7+ non-Annotated"188189 !!! tip190 Prefer to use the `Annotated` version if possible.191
48 unmodified lines
240You can override the `mode` from the defaults above.241242For example, you could use `mode="a"` to write "appending" to the same file:243244=== "Python 3.6+"244=== "Python 3.7+"245246 ```Python hl_lines="5"247 {!> ../docs_src/parameter_types/file/tutorial005_an.py!}248 ```249250=== "Python 3.6+ non-Annotated"250=== "Python 3.7+ non-Annotated"251252 !!! tip253 Prefer to use the `Annotated` version if possible.254
49 unmodified lines
modified:docs/tutorial/parameter-types/number.md+6 added-6 removed
1You can define numeric validations with `max` and `min` values for `int` and `float` *CLI parameters*:23=== "Python 3.6+"3=== "Python 3.7+"45 ```Python hl_lines="6-8"6 {!> ../docs_src/parameter_types/number/tutorial001_an.py!}7 ```89=== "Python 3.6+ non-Annotated"9=== "Python 3.7+ non-Annotated"1011 !!! tip12 Prefer to use the `Annotated` version if possible.13
69 unmodified lines
83You might want to, instead of showing an error, use the closest minimum or maximum valid values.8485You can do it with the `clamp` parameter:8687=== "Python 3.6+"87=== "Python 3.7+"8889 ```Python hl_lines="6-8"90 {!> ../docs_src/parameter_types/number/tutorial002_an.py!}91 ```9293=== "Python 3.6+ non-Annotated"93=== "Python 3.7+ non-Annotated"9495 !!! tip96 Prefer to use the `Annotated` version if possible.97
27 unmodified lines
125## Counter *CLI options*126127You can make a *CLI option* work as a counter with the `counter` parameter:128129=== "Python 3.6+"129=== "Python 3.7+"130131 ```Python hl_lines="5"132 {!> ../docs_src/parameter_types/number/tutorial003_an.py!}133 ```134135=== "Python 3.6+ non-Annotated"135=== "Python 3.7+ non-Annotated"136137 !!! tip138 Prefer to use the `Annotated` version if possible.139
43 unmodified lines
modified:docs/tutorial/parameter-types/path.md+4 added-4 removed
1You can declare a *CLI parameter* to be a standard Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" class="external-link" target="_blank">`pathlib.Path`</a>.23This is what you would do for directory paths, file paths, etc:45=== "Python 3.6+"5=== "Python 3.7+"67 ```Python hl_lines="1 8"8 {!> ../docs_src/parameter_types/path/tutorial001_an.py!}9 ```1011=== "Python 3.6+ non-Annotated"11=== "Python 3.7+ non-Annotated"1213 !!! tip14 Prefer to use the `Annotated` version if possible.15
53 unmodified lines
69 All these parameters come directly from <a href="https://click.palletsprojects.com/en/7.x/parameters/#parameter-types" class="external-link" target="_blank">Click</a>.7071For example:7273=== "Python 3.6+"73=== "Python 3.7+"7475 ```Python hl_lines="11-16"76 {!> ../docs_src/parameter_types/path/tutorial002_an.py!}77 ```7879=== "Python 3.6+ non-Annotated"79=== "Python 3.7+ non-Annotated"8081 !!! tip82 Prefer to use the `Annotated` version if possible.83
44 unmodified lines
modified:docs/tutorial/options-autocompletion.md+18 added-18 removed
12 unmodified lines
13To check it quickly without creating a new Python package, install [Typer CLI](../typer-cli.md){.internal-link target=_blank}.1415Then let's create small example program:1617=== "Python 3.6+"17=== "Python 3.7+"1819 ```Python20 {!> ../docs_src/options_autocompletion/tutorial001_an.py!}21 ```2223=== "Python 3.6+ non-Annotated"23=== "Python 3.7+ non-Annotated"2425 !!! tip26 Prefer to use the `Annotated` version if possible.27
32 unmodified lines
60Right now we get completion for the *CLI option* names, but not for the values.6162We can provide completion for the values creating an `autocompletion` function, similar to the `callback` functions from [CLI Option Callback and Context](./options/callback-and-context.md){.internal-link target=_blank}:6364=== "Python 3.6+"64=== "Python 3.7+"6566 ```Python hl_lines="5-6 15"67 {!> ../docs_src/options_autocompletion/tutorial002_an.py!}68 ```6970=== "Python 3.6+ non-Annotated"70=== "Python 3.7+ non-Annotated"7172 !!! tip73 Prefer to use the `Annotated` version if possible.74
27 unmodified lines
102Modify the `complete_name()` function to receive a parameter of type `str`, it will contain the incomplete value.103104Then we can check and return only the values that start with the incomplete value from the command line:105106=== "Python 3.6+"106=== "Python 3.7+"107108 ```Python hl_lines="7-12"109 {!> ../docs_src/options_autocompletion/tutorial003_an.py!}110 ```111112=== "Python 3.6+ non-Annotated"112=== "Python 3.7+ non-Annotated"113114 !!! tip115 Prefer to use the `Annotated` version if possible.116
34 unmodified lines
151In the `complete_name()` function, instead of providing one `str` per completion element, we provide a `tuple` with 2 items. The first item is the actual completion string, and the second item is the help text.152153So, in the end, we return a `list` of `tuples` of `str`:154155=== "Python 3.6+"155=== "Python 3.7+"156157 ```Python hl_lines="4-8 11-17"158 {!> ../docs_src/options_autocompletion/tutorial004_an.py!}159 ```160161=== "Python 3.6+ non-Annotated"161=== "Python 3.7+ non-Annotated"162163 !!! tip164 Prefer to use the `Annotated` version if possible.165
33 unmodified lines
199Instead of creating and returning a list with values (`str` or `tuple`), we can use `yield` with each value that we want in the completion.200201That 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:202203=== "Python 3.6+"203=== "Python 3.7+"204205 ```Python hl_lines="11-14"206 {!> ../docs_src/options_autocompletion/tutorial005_an.py!}207 ```208209=== "Python 3.6+ non-Annotated"209=== "Python 3.7+ non-Annotated"210211 !!! tip212 Prefer to use the `Annotated` version if possible.213
25 unmodified lines
239 So, for now, take this as a sneak peek 😉.240241For this we use a `List` of `str`:242243=== "Python 3.6+"243=== "Python 3.7+"244245 ```Python hl_lines="9-14"246 {!> ../docs_src/options_autocompletion/tutorial006_an.py!}247 ```248249=== "Python 3.6+ non-Annotated"249=== "Python 3.7+ non-Annotated"250251 !!! tip252 Prefer to use the `Annotated` version if possible.253
23 unmodified lines
277But you can access the context by declaring a function parameter of type `typer.Context`.278279And from that context you can get the current values for each parameter.280281=== "Python 3.6+"281=== "Python 3.7+"282283 ```Python hl_lines="13-14 16"284 {!> ../docs_src/options_autocompletion/tutorial007_an.py!}285 ```286287=== "Python 3.6+ non-Annotated"287=== "Python 3.7+ non-Annotated"288289 !!! tip290 Prefer to use the `Annotated` version if possible.291
65 unmodified lines
357You can print to "standard error" with a **Rich** `Console(stderr=True)`.358359Using `stderr=True` tells **Rich** that the output should be shown in "standard error".360361=== "Python 3.6+"361=== "Python 3.7+"362363 ```Python hl_lines="13 16-17"364 {!> ../docs_src/options_autocompletion/tutorial008_an.py!}365 ```366367=== "Python 3.6+ non-Annotated"367=== "Python 3.7+ non-Annotated"368369 !!! tip370 Prefer to use the `Annotated` version if possible.371
37 unmodified lines
409## Getting the Context and the raw *CLI parameters*410411Of course, you can declare everything if you need it, the context, the raw *CLI parameters*, and the incomplete `str`:412413=== "Python 3.6+"413=== "Python 3.7+"414415 ```Python hl_lines="16"416 {!> ../docs_src/options_autocompletion/tutorial009_an.py!}417 ```418419=== "Python 3.6+ non-Annotated"419=== "Python 3.7+ non-Annotated"420421 !!! tip422 Prefer to use the `Annotated` version if possible.423
42 unmodified lines
modified:docs/tutorial/package.md+13 added-13 removed
50 unmodified lines
51```console52$ poetry add "typer[all]"5354// It creates a virtual environment for your project55Creating virtualenv rick-portal-gun-w31dJa0b-py3.6 in /home/rick/.cache/pypoetry/virtualenvs55Creating virtualenv rick-portal-gun-w31dJa0b-py3.10 in /home/rick/.cache/pypoetry/virtualenvs56Using version ^0.1.0 for typer5758Updating dependencies59Resolving dependencies... (1.2s)
22 unmodified lines
8283// Activate that new virtual environment84$ poetry shell8586Spawning shell within /home/rick/.cache/pypoetry/virtualenvs/rick-portal-gun-w31dJa0b-py3.686Spawning shell within /home/rick/.cache/pypoetry/virtualenvs/rick-portal-gun-w31dJa0b-py3.108788// Open an editor using this new environment, for example VS Code89$ code ./90```
82 unmodified lines
173description = ""174authors = ["Rick Sanchez <rick@example.com>"]175176[tool.poetry.dependencies]177python = "^3.6"177python = "^3.10"178typer = {extras = ["all"], version = "^0.1.0"}179180[tool.poetry.dev-dependencies]181pytest = "^5.2"
15 unmodified lines
197authors = ["Rick Sanchez <rick@example.com>"]198readme = "README.md"199200[tool.poetry.dependencies]201python = "^3.6"201python = "^3.10"202typer = {extras = ["all"], version = "^0.1.0"}203204[tool.poetry.dev-dependencies]205pytest = "^5.2"
22 unmodified lines
228[tool.poetry.scripts]229rick-portal-gun = "rick_portal_gun.main:app"230231[tool.poetry.dependencies]232python = "^3.6"232python = "^3.10"233typer = {extras = ["all"], version = "^0.1.0"}234235[tool.poetry.dev-dependencies]236pytest = "^5.2"
64 unmodified lines
301// You can use the which program to check which rick-portal-gun program is available (if any)302$ which rick-portal-gun303304// You get the one from your environment305/home/rick/.cache/pypoetry/virtualenvs/rick-portal-gun-w31dJa0b-py3.6/bin/rick-portal-gun305/home/rick/.cache/pypoetry/virtualenvs/rick-portal-gun-w31dJa0b-py3.10/bin/rick-portal-gun306307// Try it308$ rick-portal-gun309
349 unmodified lines
659Found existing installation: rick-portal-gun 0.1.0660Uninstalling rick-portal-gun-0.1.0:661 Would remove:662 /home/user/.local/bin/rick-portal-gun663 /home/user/.local/lib/python3.6/site-packages/rick_portal_gun-0.1.0.dist-info/*664 /home/user/.local/lib/python3.6/site-packages/rick_portal_gun/*663 /home/user/.local/lib/python3.10/site-packages/rick_portal_gun-0.1.0.dist-info/*664 /home/user/.local/lib/python3.10/site-packages/rick_portal_gun/*665# Proceed (y/n)? $ y666 Successfully uninstalled rick-portal-gun-0.1.0667```668
8 unmodified lines
677678// Notice that it says "Downloading" 🚀679Collecting rick-portal-gun680 Downloading rick_portal_gun-0.1.0-py3-none-any.whl (1.8 kB)681Requirement already satisfied: typer[all]<0.0.12,>=0.0.11 in ./.local/lib/python3.6/site-packages (from rick-portal-gun) (0.0.11)682Requirement already satisfied: click<7.2.0,>=7.1.1 in ./anaconda3/lib/python3.6/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (7.1.1)683Requirement already satisfied: colorama; extra == "all" in ./anaconda3/lib/python3.6/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (0.4.3)684Requirement already satisfied: shellingham; extra == "all" in ./anaconda3/lib/python3.6/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (1.3.1)681Requirement already satisfied: typer[all]<0.0.12,>=0.0.11 in ./.local/lib/python3.10/site-packages (from rick-portal-gun) (0.0.11)682Requirement already satisfied: click<7.2.0,>=7.1.1 in ./anaconda3/lib/python3.10/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (7.1.1)683Requirement already satisfied: colorama; extra == "all" in ./anaconda3/lib/python3.10/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (0.4.3)684Requirement already satisfied: shellingham; extra == "all" in ./anaconda3/lib/python3.10/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (1.3.1)685Installing collected packages: rick-portal-gun686Successfully installed rick-portal-gun-0.1.0687```688
49 unmodified lines
738[tool.poetry.scripts]739rick-portal-gun = "rick_portal_gun.main:app"740741[tool.poetry.dependencies]742python = "^3.6"742python = "^3.10"743typer = {extras = ["all"], version = "^0.1.0"}744745[tool.poetry.dev-dependencies]746pytest = "^5.2"
54 unmodified lines
modified:docs/tutorial/testing.md+3 added-3 removed
83 unmodified lines
84```console85$ pytest8687================ test session starts ================88platform linux -- Python 3.6.9, pytest-5.3.5, py-1.8.1, pluggy-0.13.188platform linux -- Python 3.10, pytest-5.3.5, py-1.8.1, pluggy-0.13.189rootdir: /home/user/code/superawesome-cli/app90plugins: forked-1.1.3, xdist-1.31.0, cov-2.8.191collected 1 item92
9 unmodified lines
102## Testing input103104If you have a CLI with prompts, like:105106=== "Python 3.6+"106=== "Python 3.7+"107108 ```Python hl_lines="8"109 {!> ../docs_src/testing/app02_an/main.py!}110 ```111112=== "Python 3.6+ non-Annotated"112=== "Python 3.7+ non-Annotated"113114 !!! tip115 Prefer to use the `Annotated` version if possible.116
108 unmodified lines
modified:docs/features.md+1 added-1 removed
6 unmodified lines
7It follows the same design and ideas. If you know **FastAPI**, you already know **Typer**... more or less.89## Just Modern Python1011It's all based on standard **Python 3.6 type** declarations. No new syntax to learn. Just standard modern Python.11It's all based on standard **Python type** declarations. No new syntax to learn. Just standard modern Python.1213If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI or Typer), check the FastAPI tutorial section: <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">Python types intro</a>.1415You will also see a 20 seconds refresher on the section [Tutorial - User Guide: First Steps](tutorial/first-steps.md){.internal-link target=_blank}.
70 unmodified lines
modified:docs/index.md+2 added-4 removed
24 unmodified lines
25**Source Code**: <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>2627---2829Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python 3.6+ type hints.29Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python type hints.3031The key features are:3233* **Intuitive to write**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.
11 unmodified lines
45And it's intended to be the FastAPI of CLIs.4647## Requirements4849Python 3.6+5049**Typer** stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a>.5051## Installation52
221 unmodified lines
274You do that with standard modern Python types.275276You don't have to learn a new syntax, the methods or classes of a specific library, etc.277280Just standard **Python 3.6+**.278Just standard **Python**.279280For example, for an `int`:281282```Python
33 unmodified lines
deleted:scripts/netlify-docs.sh-14 removed
1#!/usr/bin/env bash2set -x3set -e4# Install pip5cd /tmp6curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py7python3.6 get-pip.py --user8cd -9# Install Flit to be able to install all10python3.6 -m pip install --user flit11# Install with Flit12python3.6 -m flit install --user --deps develop13# Finally, run mkdocs14python3.6 -m mkdocs build
modified:tests/test_tutorial/test_exceptions/test_tutorial001.py+2 added-12 removed
21 unmodified lines
22 assert "return get_command(self)(*args, **kwargs)" not in result.stderr2324 assert "typer.run(main)" not in result.stderr25 assert "print(name + 3)" in result.stderr2627 # TODO: when deprecating Python 3.6, remove second option28 assert (29 'TypeError: can only concatenate str (not "int") to str' in result.stderr26 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr30 or "TypeError: must be str, not int" in result.stderr31 )27 assert "name = 'morty'" in result.stderr282930def test_standard_traceback_env_var():
8 unmodified lines
39 assert "return get_command(self)(*args, **kwargs)" in result.stderr4041 assert "typer.run(main)" in result.stderr42 assert "print(name + 3)" in result.stderr4849 # TODO: when deprecating Python 3.6, remove second option50 assert (51 'TypeError: can only concatenate str (not "int") to str' in result.stderr43 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr52 or "TypeError: must be str, not int" in result.stderr53 )44 assert "name = 'morty'" not in result.stderr454647def test_script():
7 unmodified lines
modified:tests/test_tutorial/test_exceptions/test_tutorial002.py+2 added-12 removed
21 unmodified lines
22 assert "return get_command(self)(*args, **kwargs)" not in result.stderr2324 assert "app()" not in result.stderr25 assert "print(password + 3)" in result.stderr2627 # TODO: when deprecating Python 3.6, remove second option28 assert (29 'TypeError: can only concatenate str (not "int") to str' in result.stderr26 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr30 or "TypeError: must be str, not int" in result.stderr31 )27 assert "name = 'morty'" not in result.stderr282930def test_standard_traceback_env_var():
8 unmodified lines
39 assert "return get_command(self)(*args, **kwargs)" in result.stderr4041 assert "app()" in result.stderr42 assert "print(password + 3)" in result.stderr4849 # TODO: when deprecating Python 3.6, remove second option50 assert (51 'TypeError: can only concatenate str (not "int") to str' in result.stderr43 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr52 or "TypeError: must be str, not int" in result.stderr53 )44 assert "name = 'morty'" not in result.stderr454647def test_script():
7 unmodified lines
modified:tests/test_tutorial/test_exceptions/test_tutorial003.py+1 added-6 removed
21 unmodified lines
22 assert "return get_command(self)(*args, **kwargs)" not in result.stderr2324 assert "app()" in result.stderr25 assert "print(name + 3)" in result.stderr2627 # TODO: when deprecating Python 3.6, remove second option28 assert (29 'TypeError: can only concatenate str (not "int") to str' in result.stderr26 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr30 or "TypeError: must be str, not int" in result.stderr31 )27 assert "name = 'morty'" in result.stderr282930def test_script():
7 unmodified lines
modified:tests/test_tutorial/test_exceptions/test_tutorial004.py+1 added-5 removed
21 unmodified lines
22 assert "return get_command(self)(*args, **kwargs)" in result.stderr2324 assert "app()" in result.stderr25 assert "print(name + 3)" in result.stderr26 # TODO: when deprecating Python 3.6, remove second option27 assert (28 'TypeError: can only concatenate str (not "int") to str' in result.stderr26 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr29 or "TypeError: must be str, not int" in result.stderr30 )272829def test_script():30 result = subprocess.run(
6 unmodified lines
modified:tests/test_tracebacks.py+3 added-15 removed
15 unmodified lines
16 assert "return get_command(self)(*args, **kwargs)" not in result.stderr1718 assert "typer.run(main)" in result.stderr19 assert "print(name + 3)" in result.stderr20 # TODO: when deprecating Python 3.6, remove second option21 assert (22 'TypeError: can only concatenate str (not "int") to str' in result.stderr20 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr23 or "TypeError: must be str, not int" in result.stderr24 )212223def test_traceback_no_rich_short_disable():24 file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py"
7 unmodified lines
32 assert "return get_command(self)(*args, **kwargs)" not in result.stderr3334 assert "app()" in result.stderr35 assert "print(name + 3)" in result.stderr40 # TODO: when deprecating Python 3.6, remove second option41 assert (42 'TypeError: can only concatenate str (not "int") to str' in result.stderr36 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr43 or "TypeError: must be str, not int" in result.stderr44 )373839def test_unmodified_traceback():40 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py"
10 unmodified lines
51 "even after the hook is installed"52 )53 assert "typer.main.get_command(broken_app)()" in result.stderr54 assert "print(name + 3)" in result.stderr63 # TODO: when deprecating Python 3.6, remove second option64 assert (65 'TypeError: can only concatenate str (not "int") to str' in result.stderr55 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr66 or "TypeError: must be str, not int" in result.stderr67 )
modified:.gitignore+1 added-2 removed
1.vscode2*.pyc3__pycache__4env3.75env3.64.venv*5env6dist7.mypy_cache8.idea
5 unmodified lines
modified:pyproject.toml+1 added-2 removed
19 unmodified lines
20 "Typing :: Typed",21 "Development Status :: 4 - Beta",22 "Intended Audience :: Developers",23 "Programming Language :: Python :: 3 :: Only",24 "Programming Language :: Python :: 3.6",24 "Programming Language :: Python :: 3.7",25 "Programming Language :: Python :: 3.8",26 "Programming Language :: Python :: 3.9",27 "Programming Language :: Python :: 3.10",
4 unmodified lines
32 "click >= 7.1.1, <9.0.0",33 "typing-extensions >= 3.7.4.3",34]35description-file = "README.md"37requires-python = ">=3.6"36requires-python = ">=3.7"3738[tool.flit.metadata.urls]39Documentation = "https://typer.tiangolo.com/"40
55 unmodified lines
modified:README.md+2 added-4 removed
24 unmodified lines
25**Source Code**: <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>2627---2829Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python 3.6+ type hints.29Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python type hints.3031The key features are:3233* **Intuitive to write**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.
11 unmodified lines
45And it's intended to be the FastAPI of CLIs.4647## Requirements4849Python 3.6+5049**Typer** stands on the shoulders of a giant. Its only internal dependency is <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a>.5051## Installation52
221 unmodified lines
274You do that with standard modern Python types.275276You don't have to learn a new syntax, the methods or classes of a specific library, etc.277280Just standard **Python 3.6+**.278Just standard **Python**.279280For example, for an `int`:281282```Python
33 unmodified lines