-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathbase.py
48 lines (36 loc) · 1.16 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Defines base classes to be used all requirements"""
from __future__ import annotations
from abc import abstractmethod, ABC
from dataclasses import dataclass
from typing import Any
from pydantic import Json
class AbstractRequirement(ABC):
"""Base class all requirements should inherit from
When implementing, define your own TypedDict dervied type to override from_json()
"""
@abstractmethod
def attempt_fulfill(self, course: str) -> bool:
pass
@abstractmethod
def is_fulfilled(self) -> bool:
pass
@abstractmethod
def override_fill(self, index: str) -> bool:
pass
@dataclass
class JSON(ABC):
matcher: str
metadata: dict[str, Any]
@classmethod
@abstractmethod
def from_json(cls, json: Any) -> AbstractRequirement:
"""Creates a requirement from a json map
Takes in json map with the structure of { "matcher": "SomeMatcher", ... }
"""
pass
@abstractmethod
def to_json(self) -> Json[Any]:
"""Converts the requirement into JSON-serializable format
Includes all the attributes within a Requirement class
"""
pass