Coverage for docs_src / terminating / tutorial001_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 

3existing_usernames = ["rick", "morty"] 1abcdefgh

4 

5 

6def maybe_create_user(username: str): 1abcdefgh

7 if username in existing_usernames: 1abcdefgh

8 print("The user already exists") 1abcdefgh

9 raise typer.Exit() 1abcdefgh

10 else: 

11 print(f"User created: {username}") 1abcdefgh

12 

13 

14def send_new_user_notification(username: str): 1abcdefgh

15 # Somehow send a notification here for the new user, maybe an email 

16 print(f"Notification sent for new user: {username}") 1abcdefgh

17 

18 

19app = typer.Typer() 1abcdefgh

20 

21 

22@app.command() 1abcdefgh

23def main(username: str): 1abcdefgh

24 maybe_create_user(username=username) 1abcdefgh

25 send_new_user_notification(username=username) 1abcdefgh

26 

27 

28if __name__ == "__main__": 1abcdefgh

29 app() 1abcdefgh