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

12 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +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 

19def main(username: str): 1abcdefgh

20 maybe_create_user(username=username) 1abcdefgh

21 send_new_user_notification(username=username) 1abcdefgh

22 

23 

24if __name__ == "__main__": 1abcdefgh

25 typer.run(main) 1abcdefgh