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

12 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1import typer 1abcdefghi

2 

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

4 

5 

6def maybe_create_user(username: str): 1abcdefghi

7 if username in existing_usernames: 1abcdefghi

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

9 raise typer.Exit() 1abcdefghi

10 else: 

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

12 

13 

14def send_new_user_notification(username: str): 1abcdefghi

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

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

17 

18 

19def main(username: str): 1abcdefghi

20 maybe_create_user(username=username) 1abcdefghi

21 send_new_user_notification(username=username) 1abcdefghi

22 

23 

24if __name__ == "__main__": 1abcdefghi

25 typer.run(main) 1abcdefghi