diff options
Diffstat (limited to 'aoc/__init__.py')
| -rw-r--r-- | aoc/__init__.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/aoc/__init__.py b/aoc/__init__.py index 8368f7b..7a089f6 100644 --- a/aoc/__init__.py +++ b/aoc/__init__.py | |||
| @@ -1,11 +1,15 @@ | |||
| 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
| 2 | import os | 2 | import os |
| 3 | from abc import ABC | 3 | from abc import ABC |
| 4 | from typing import Generator, Any, Iterator | 4 | from typing import Generator, Any, Iterator, Dict, TypeVar, Generic |
| 5 | 5 | ||
| 6 | T = TypeVar("T") | ||
| 7 | I = TypeVar("I") | ||
| 6 | 8 | ||
| 7 | class BaseAssignment(ABC): | 9 | |
| 8 | example_result = NotImplemented | 10 | class BaseAssignment(Generic[T, I], ABC): |
| 11 | example_result: T = NotImplemented | ||
| 12 | example_kwargs: Dict = {} | ||
| 9 | 13 | ||
| 10 | def __init__(self, path): | 14 | def __init__(self, path): |
| 11 | self.path = path | 15 | self.path = path |
| @@ -13,14 +17,14 @@ class BaseAssignment(ABC): | |||
| 13 | def __str__(self): | 17 | def __str__(self): |
| 14 | return f"{self.__module__}.{self.__class__.__name__}" | 18 | return f"{self.__module__}.{self.__class__.__name__}" |
| 15 | 19 | ||
| 16 | def parse_item(self, item: str) -> Any: | 20 | def parse_item(self, item: str) -> I: |
| 17 | return item | 21 | return item |
| 18 | 22 | ||
| 19 | @property | 23 | @property |
| 20 | def part(self): | 24 | def part(self) -> int: |
| 21 | return 1 if self.__class__.__name__.endswith("One") else 2 | 25 | return 1 if self.__class__.__name__.endswith("One") else 2 |
| 22 | 26 | ||
| 23 | def read_input(self, example=False) -> Generator: | 27 | def read_input(self, example=False) -> Iterator[I]: |
| 24 | file = f"{self.path}/input.txt" | 28 | file = f"{self.path}/input.txt" |
| 25 | 29 | ||
| 26 | if example or not os.path.isfile(file): | 30 | if example or not os.path.isfile(file): |
| @@ -35,5 +39,5 @@ class BaseAssignment(ABC): | |||
| 35 | for line in input_file.readlines(): | 39 | for line in input_file.readlines(): |
| 36 | yield self.parse_item(line.strip("\n")) | 40 | yield self.parse_item(line.strip("\n")) |
| 37 | 41 | ||
| 38 | def run(self, input: Iterator) -> Any: | 42 | def run(self, input: Iterator[I]) -> T: |
| 39 | raise NotImplementedError("Please implement run") | 43 | raise NotImplementedError("Please implement run") |
