type annotations

This commit is contained in:
Stefan Harmuth 2021-11-21 13:10:10 +01:00
parent 2b8a69c24b
commit af48c1a8fb

View File

@ -1,5 +1,5 @@
import os import os
from typing import List, Any from typing import List, Any, Type
from .tools import splitLine from .tools import splitLine
from .output import printSolution from .output import printSolution
@ -13,7 +13,7 @@ class AOCDay:
test_solutions_p1: List test_solutions_p1: List
test_solutions_p2: List test_solutions_p2: List
def __init__(self, day): def __init__(self, day: int):
self.day = day self.day = day
with open(os.path.join(INPUTS_PATH, "input%02d" % day)) as f: with open(os.path.join(INPUTS_PATH, "input%02d" % day)) as f:
self.input = f.read().splitlines() self.input = f.read().splitlines()
@ -52,13 +52,13 @@ class AOCDay:
self.input = live_input self.input = live_input
return True return True
def getInputListAsType(self, return_type): def getInputListAsType(self, return_type: Type) -> List:
""" """
get input as list casted to return_type, each line representing one list entry get input as list casted to return_type, each line representing one list entry
""" """
return [return_type(i) for i in self.input] return [return_type(i) for i in self.input]
def getMultiLineInputAsArray(self, return_type=None, join_char=None): def getMultiLineInputAsArray(self, return_type: Type = None, join_char: str = None) -> List:
""" """
get input for day x as 2d array, split by empty lines get input for day x as 2d array, split by empty lines
""" """
@ -83,7 +83,7 @@ class AOCDay:
return return_array return return_array
def getInputAs2DArray(self, return_type=None): def getInputAs2DArray(self, return_type: Type = None) -> List:
""" """
get input for day x as 2d-array (a[line][pos]) get input for day x as 2d-array (a[line][pos])
""" """
@ -96,7 +96,7 @@ class AOCDay:
return return_array return return_array
def getInputAsArraySplit(self, split_char=',', return_type=None): def getInputAsArraySplit(self, split_char: str = ',', return_type: Type = None) -> List:
""" """
get input for day x with the lines split by split_char get input for day x with the lines split by split_char
if input has only one line, returns a 1d array with the values if input has only one line, returns a 1d array with the values