Skip to content

Commit

Permalink
Remove name parameter from callback
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Nov 20, 2024
1 parent 08552ee commit 3313794
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion docs/tutorial/subcommands/name-and-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ The precedence to generate a command's name and help, from lowest priority to hi
* Implicitly inferred from the callback function under `@sub_app.callback()` (only the help text)
* Implicitly inferred from `app.add_typer(sub_app, callback=some_function)` (only the help text)
* Explicitly set on `sub_app = typer.Typer(name="some-name", help="Some help.")`
* Explicitly set on `@sub_app.callback("some-name", help="Some help.")`
* Explicitly set on `app.add_typer(sub_app, name="some-name", help="Some help.")`

So, `app.add_typer(sub_app, name="some-name", help="Some help.")` always wins.
3 changes: 1 addition & 2 deletions docs_src/subcommands/name_help/tutorial007.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def new_users():
app.add_typer(users_app, callback=new_users)


# TODO: do we want this to work?
@users_app.callback("call-users", help="Help from callback for users.")
@users_app.callback(help="Help from callback for users.")
def users():
"""
Manage users in the app.
Expand Down
2 changes: 1 addition & 1 deletion docs_src/subcommands/name_help/tutorial008.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def new_users():
)


@users_app.callback("call-users", help="Help from callback for users.")
@users_app.callback(help="Help from callback for users.")
def users():
"""
Manage users in the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "Commands" in result.output
assert "call-users" in result.output
assert "users" in result.output
assert "Help from callback for users." in result.output


Expand Down
2 changes: 0 additions & 2 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def __init__(

def callback(
self,
name: Optional[str] = Default(None),
*,
cls: Optional[Type[TyperGroup]] = Default(None),
invoke_without_command: bool = Default(False),
Expand All @@ -206,7 +205,6 @@ def callback(
) -> Callable[[CommandFunctionType], CommandFunctionType]:
def decorator(f: CommandFunctionType) -> CommandFunctionType:
self.registered_callback = TyperInfo(
name=name,
cls=cls,
invoke_without_command=invoke_without_command,
no_args_is_help=no_args_is_help,
Expand Down

0 comments on commit 3313794

Please sign in to comment.