Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created March 9, 2025 20:27
Show Gist options
  • Save mypy-play/14389bb0e8796f25baa1739b46e3382c to your computer and use it in GitHub Desktop.
Save mypy-play/14389bb0e8796f25baa1739b46e3382c to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from __future__ import annotations
from enum import Enum
from typing import Type
menu_msg : str = \
"""
Please select a valid size (1-3):
1. Small
2. Medium
3. Large
"""
class Size(Enum):
Small = 1
Medium = 2
Large = 3
@classmethod
def prompt_size(cls : Type[Size], prmpt : str) -> Size:
while True:
try:
size: Size = Size(int(input(prmpt)))
return size
except ValueError as ex:
print(ex)
print(Size.prompt_size(menu_msg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment