Skip to content

Instantly share code, notes, and snippets.

@inesp
Created September 2, 2019 13:26
Show Gist options
  • Save inesp/6df30fe26108a673db49e3b04821e519 to your computer and use it in GitHub Desktop.
Save inesp/6df30fe26108a673db49e3b04821e519 to your computer and use it in GitHub Desktop.
from dataclasses import dataclass, field
from enum import Enum
from typing import List, Optional
from datetime import date
from models import Animal, Person
# 1. We define an Enum of possible weekday names
class WeekDay(Enum):
MON = "Monday"
WED = "Wednesday"
FRI = "Friday"
# 2. We collect all key-value pairs from all _get_config functions
# and define a ZooInfo dataclass with type hints and default values.
@dataclass
class ZooOutline:
owner_name: str
size: int
animals: List[Animal]
free_entrance_day: WeekDay = field(default=WeekDay.MON)
# As you can see this field is not meant to be None, it was
# not marked as Optional. It does not, however, need to be
# specified. It will default to Monday.
most_popular_animal: Optional[Animal] = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment