Skip to content

Instantly share code, notes, and snippets.

@Diapolo10
Last active October 22, 2024 15:05
Show Gist options
  • Save Diapolo10/78dde1b33390b4aa9ca216ec6dffe1bc to your computer and use it in GitHub Desktop.
Save Diapolo10/78dde1b33390b4aa9ca216ec6dffe1bc to your computer and use it in GitHub Desktop.
Allergies flag enum
from __future__ import annotations
from enum import CONFORM, Flag, auto
class Allergies(Flag, boundary=CONFORM):
EGGS = auto()
PEANUTS = auto()
SHELLFISH = auto()
STRAWBERRIES = auto()
TOMATOES = auto()
CHOCOLATE = auto()
POLLEN = auto()
CATS = auto()
def allergic_to(self, item: str) -> bool:
return type(self)[item.upper()] in self
@property
def lst(self) -> list[str]:
return [allergy.name.lower() for allergy in self]
@Diapolo10
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment