Skip to content

Instantly share code, notes, and snippets.

@dogweather
Last active October 4, 2022 01:26
Show Gist options
  • Save dogweather/af994d9c8369cad01b8b74465995b9ae to your computer and use it in GitHub Desktop.
Save dogweather/af994d9c8369cad01b8b74465995b9ae to your computer and use it in GitHub Desktop.
from enum import Enum
from typing import NoReturn
class Color(Enum):
RED = "RED"
GREEN = "GREEN"
BLUE = "BLUE" # I just added this
def handle_color(color: Color) -> None:
if color is Color.RED:
...
elif color is Color.GREEN:
...
else:
assert_never(color)
def assert_never(value: NoReturn) -> NoReturn:
assert False, f"Unknown value: {value}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment