Skip to content

Instantly share code, notes, and snippets.

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"
@inesp
inesp / zoo.py
Created September 2, 2019 13:23
from datetime import datetime
from models import Person
class Zoo:
def __init__(zoo_config):
self._owner_name = zoo_config["owner"]
# 1. owner appears to be mandatory, it is actually the owner's name
self._free_entrance_day = zoo_confi.get("free_entrance_day", "Monday")
# 2. free_entrance_day is not mandatory, it must be the english name
# for a week day, can I set it to None in zoo_config or will this
class City:
# 1. add type hints, here we see that name shouldn't* be None
name: str = "vienna"
# 2. add more type hints
def create_zoo(self, owner: str) -> Optional[Zoo]:
zoo_configs: Dict[
str, ZooConfiguration
] = ZOOsConfigBuilder().get_configs()
TCityName = str
class ZOOsConfigBuilder:
def get_configs(self) -> Dict[TCityName, ZooConfiguration]:
return {
"paris": ZooConfiguration(
is_open_to_public=True,
get_config=self:_build_paris_config(["girrafe", "lion", "ape"]),
),
@inesp
inesp / zoo_configuration.py
Last active September 2, 2019 13:20
ZooConfiguration dataclass
from dataclasses import dataclass
from typing import Callable, Dict
TZooOwnerName = str
TZooSize = int
@dataclass
class ZooConfiguration:
is_open_to_public: bool
get_config: Callable[[TZooOwnerName, TZooSize], Dict]
@inesp
inesp / zoos.py
Last active September 2, 2019 13:17
The ZOO of configs
# ----------- File zoos_config_builder.py -----------------
from functools import partial
class ZOOsConfigBuilder:
...
def get_config(self):
return {