Skip to content

Instantly share code, notes, and snippets.

@2tony2
Created May 22, 2024 07:38
Show Gist options
  • Select an option

  • Save 2tony2/b341b15c811475a15b3386751f0db93e to your computer and use it in GitHub Desktop.

Select an option

Save 2tony2/b341b15c811475a15b3386751f0db93e to your computer and use it in GitHub Desktop.
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