Created
May 22, 2024 07:38
-
-
Save 2tony2/b341b15c811475a15b3386751f0db93e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Literal | |
| def set_environment(env: Literal["development", "staging", "production"]) -> str: | |
| return f"Environment set to {env}" | |
| print(set_environment("development")) # Output: Environment set to development | |
| print(set_environment("production")) # Output: Environment set to production | |
| # The following would raise a type error with a type checker like mypy, as "test" is not a valid literal | |
| # print(set_environment("test")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment