Coverage for docs_src / terminating / tutorial001.py: 100%

14 statements  

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

1import typer 1abcdefghij

2 

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

4 

5 

6def maybe_create_user(username: str): 1abcdefghij

7 if username in existing_usernames: 1abcdefghij

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

9 raise typer.Exit() 1abcdefghij

10 else: 

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

12 

13 

14def send_new_user_notification(username: str): 1abcdefghij

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

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

17 

18 

19app = typer.Typer() 1abcdefghij

20 

21 

22@app.command() 1abcdefghij

23def main(username: str): 1abcdefghij

24 maybe_create_user(username=username) 1abcdefghij

25 send_new_user_notification(username=username) 1abcdefghij

26 

27 

28if __name__ == "__main__": 1abcdefghij

29 app() 1abcdefghij