Coverage for docs_src / subcommands / callback_override / tutorial004_py39.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-02-09 12:36 +0000

1import typer 1abcdefgh

2 

3app = typer.Typer() 1abcdefgh

4 

5 

6def default_callback(): 1abcdefgh

7 print("Running a users command") 1abcdefgh

8 

9 

10users_app = typer.Typer(callback=default_callback) 1abcdefgh

11 

12 

13def callback_for_add_typer(): 1abcdefgh

14 print("I have the high land! Running users command") 1abcdefgh

15 

16 

17app.add_typer(users_app, name="users", callback=callback_for_add_typer) 1abcdefgh

18 

19 

20@users_app.callback() 1abcdefgh

21def user_callback(): 1abcdefgh

22 print("Callback override, running users command") 1abcdefgh

23 

24 

25@users_app.command() 1abcdefgh

26def create(name: str): 1abcdefgh

27 print(f"Creating user: {name}") 1abcdefgh

28 

29 

30if __name__ == "__main__": 1abcdefgh

31 app() 1abcdefgh