Skip to content

Commit 3176124

Browse files
committed
feat(validation): add pydantic.validate_call to input and function validation
- Imported `validate_call` from `pydantic`. - Applied `validate_call(validate_return=True)` to `cast_func` in `RunCommand` to validate input casting functions. - Applied `validate_call(validate_return=True)` to `func` in `RunCommand` to validate functions for each part. This update ensures input data and function outputs are validated for correctness during execution.
1 parent 73ae69c commit 3176124

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

aoc_run.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python
2-
import inspect
32
from functools import wraps
43
from importlib import import_module
4+
import inspect
55
from pathlib import Path
66
from timeit import timeit
77

88
from cleo import Application
99
from cleo import Command as BaseCommand
10+
from pydantic import validate_call
1011

1112

1213
ROOT_PATH = Path(__file__).resolve().parent
@@ -58,6 +59,7 @@ def handle(self):
5859
for part in parts:
5960
path = ROOT_PATH / f"{year}/{day}"
6061
cast_func = day_module.__dict__.get(f"part{part}_cast_input", day_module.__dict__["cast_input"])
62+
cast_func = validate_call(validate_return=True)(cast_func)
6163
input_file = path / f"part{part}.input"
6264
if not Path(input_file).is_file():
6365
input_file = path / "input"
@@ -67,6 +69,7 @@ def handle(self):
6769
input_data = cast_func(f.read())
6870
print(SEPERATOR + f"part-{part}")
6971
for _, func in list(filter(lambda x: x[0].endswith(f"part{part}"), funcs)):
72+
func = validate_call(validate_return=True)(func)
7073
print(
7174
SEPERATOR * 2 + f"ƒ {func.__name__}",
7275
)

0 commit comments

Comments
 (0)