Skip to content

Commit d55f9e9

Browse files
committed
Remove code and update docs
1 parent 6167f1d commit d55f9e9

2 files changed

Lines changed: 16 additions & 41 deletions

File tree

docs/tutorial/subcommands/name-and-help.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,15 @@ def create(item: str):
8181

8282
...will create a command `create` with a help text of `Create an item`.
8383

84-
### Inferring name and help from `@app.callback()`
84+
### Inferring help from `@app.callback()`
8585

8686
The same way, if you define a callback in a `typer.Typer()`, the help text is extracted from the callback function's docstring.
8787

88-
And if that Typer app is added to another Typer app, the default name of the command is generated from the name of the callback function.
89-
9088
Here's an example:
9189

9290
{* docs_src/subcommands/name_help/tutorial002.py hl[6,9,10,11,12,13] *}
9391

94-
Notice that now we added the sub-Typer without specifying a `name` nor a `help`.
95-
96-
They are now inferred from the callback function.
97-
98-
The command name will be the same callback function's name: `users`.
99-
100-
And the help text for that `users` command will be the callback function's docstring: `Manage users in the app.`.
92+
The help text for that command will be the callback function's docstring: `Manage users in the app.`.
10193

10294
Check it:
10395

@@ -107,7 +99,7 @@ Check it:
10799
// Check the main help
108100
$ python main.py --help
109101

110-
// Notice the command name "users" and the help text "Manage users in the app."
102+
// Notice the help text "Manage users in the app."
111103
Usage: main.py [OPTIONS] COMMAND [ARGS]...
112104

113105
Options:
@@ -135,9 +127,9 @@ Commands:
135127

136128
</div>
137129

138-
### Name and help from callback parameter in `typer.Typer()`
130+
### Help from callback parameter in `typer.Typer()`
139131

140-
If you pass a `callback` parameter while creating a `typer.Typer(callback=some_function)` it will be used to infer the name and help text.
132+
If you pass a `callback` parameter while creating a `typer.Typer(callback=some_function)` it will be used to infer the help text.
141133

142134
This has the lowest priority, we'll see later what has a higher priority and can override it.
143135

@@ -155,7 +147,7 @@ Check it:
155147
// Check the main help
156148
$ python main.py --help
157149

158-
// Notice the command name "users" and the help text "Manage users in the app."
150+
// Notice the help text "Manage users in the app."
159151
Usage: main.py [OPTIONS] COMMAND [ARGS]...
160152

161153
Options:
@@ -185,11 +177,11 @@ Commands:
185177

186178
### Override a callback set in `typer.Typer()` with `@app.callback()`
187179

188-
The same as with normal **Typer** apps, if you pass a `callback` to `typer.Typer(callback=some_function)` and then override it with `@app.callback()`, the name and help text will be inferred from the new callback:
180+
The same as with normal **Typer** apps, if you pass a `callback` to `typer.Typer(callback=some_function)` and then override it with `@app.callback()`, the help text will be inferred from the new callback:
189181

190182
{* docs_src/subcommands/name_help/tutorial004.py hl[16,17,18,19,20] *}
191183

192-
Now the name of the command will be `users` instead of `old-callback`, and the help text will be `Manage users in the app.` instead of `Old callback help.`.
184+
Now the help text will be `Manage users in the app.` instead of `Old callback help.`.
193185

194186
Check it:
195187

@@ -199,7 +191,7 @@ Check it:
199191
// Check the main help
200192
$ python main.py --help
201193

202-
// Notice the command name "users" and the help text "Manage users in the app."
194+
// Notice the help text "Manage users in the app."
203195
Usage: main.py [OPTIONS] COMMAND [ARGS]...
204196

205197
Options:
@@ -227,17 +219,17 @@ Commands:
227219

228220
</div>
229221

230-
### Infer name and help from callback in `app.add_typer()`
222+
### Help from callback in `app.add_typer()`
231223

232-
If you override the callback in `app.add_typer()` when including a sub-app, the name and help will be inferred from this callback function.
224+
If you override the callback in `app.add_typer()` when including a sub-app, the help will be inferred from this callback function.
233225

234-
This takes precedence over inferring the name and help from a callback set in `@sub_app.callback()` and `typer.Typer(callback=sub_app_callback)`.
226+
This takes precedence over inferring the help from a callback set in `@sub_app.callback()` and `typer.Typer(callback=sub_app_callback)`.
235227

236228
Check the code:
237229

238230
{* docs_src/subcommands/name_help/tutorial005.py hl[15,16,17,18,21] *}
239231

240-
Now the command will be `new-users` instead of `users`. And the help text will be `I have the highland! Create some users.` instead of the previous ones.
232+
The help text will be `I have the highland! Create some users.` instead of the previous ones.
241233

242234
Check it:
243235

@@ -277,13 +269,13 @@ Commands:
277269

278270
### Enough inferring
279271

280-
So, when inferring a name and help text, the precedence order from lowest priority to highest is:
272+
So, when inferring help text, the precedence order from lowest priority to highest is:
281273

282274
* `sub_app = typer.Typer(callback=some_function)`
283275
* `@sub_app.callback()`
284276
* `app.add_typer(sub_app, callback=new_function)`
285277

286-
That's for inferring the name and help text from functions.
278+
That's for inferring the help text from functions.
287279

288280
But if you set the name and help text explicitly, that has a higher priority than these.
289281

@@ -299,7 +291,7 @@ Setting the name and help text explicitly always has a higher precedence than in
299291

300292
### Name and help in `typer.Typer()`
301293

302-
You could have all the callbacks and overrides we defined before, but the name and help text was inferred from the function name and docstring.
294+
You could have all the callbacks and overrides we defined before, but the help text was inferred from the function docstring.
303295

304296
If you set it explicitly, that takes precedence over inferring.
305297

typer/main.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,6 @@ def get_command(typer_instance: Typer) -> click.Command:
389389
) # pragma: no cover
390390

391391

392-
def get_group_name(typer_info: TyperInfo) -> Optional[str]:
393-
# if typer_info.callback:
394-
# # Priority 1: Callback passed in app.add_typer()
395-
# return get_command_name(typer_info.callback.__name__)
396-
# if typer_info.typer_instance:
397-
# registered_callback = typer_info.typer_instance.registered_callback
398-
# if registered_callback:
399-
# if registered_callback.callback:
400-
# # Priority 2: Callback passed in @subapp.callback()
401-
# return get_command_name(registered_callback.callback.__name__)
402-
# if typer_info.typer_instance.info.callback:
403-
# return get_command_name(typer_info.typer_instance.info.callback.__name__)
404-
return None
405-
406-
407392
def solve_typer_info_help(typer_info: TyperInfo) -> str:
408393
# Priority 1: Explicit value was set in app.add_typer()
409394
if not isinstance(typer_info.help, DefaultPlaceholder):
@@ -480,8 +465,6 @@ def solve_typer_info_defaults(typer_info: TyperInfo) -> TyperInfo:
480465
pass
481466
# Value not set, use the default
482467
values[name] = value.value
483-
if values["name"] is None:
484-
values["name"] = get_group_name(typer_info)
485468
values["help"] = solve_typer_info_help(typer_info)
486469
return TyperInfo(**values)
487470

0 commit comments

Comments
 (0)