diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-12-04 14:12:39 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-12-04 14:12:39 +0000 |
commit | 1686a02179d67f8790dcbd3841e84be2e69d0319 (patch) | |
tree | 7c5a7ab7289924328e2b5e4ed91dc0dc6a4a7a64 | |
parent | aeacfe41d3bc2e2fa5e2a78862cc4046b9414bc3 (diff) | |
download | aoc2023-1686a02179d67f8790dcbd3841e84be2e69d0319.tar.gz aoc2023-1686a02179d67f8790dcbd3841e84be2e69d0319.tar.xz aoc2023-1686a02179d67f8790dcbd3841e84be2e69d0319.zip |
strict typing
-rw-r--r-- | 1.py | 1 | ||||
-rw-r--r-- | 2.py | 3 | ||||
-rw-r--r-- | 3.py | 1 | ||||
-rw-r--r-- | 4.py | 4 |
4 files changed, 7 insertions, 2 deletions
@@ -1,3 +1,4 @@ +# pyright: strict import re from itertools import chain from sys import stdin @@ -1,3 +1,4 @@ +# pyright: strict from dataclasses import dataclass from functools import reduce from operator import mul @@ -16,7 +17,7 @@ class Game: def parse(inp: str) -> Game: game, subsets_str = inp.rstrip().split(": ") _, game = game.split(" ") - subsets = list() + subsets: list[dict[str, int]] = list() for s in subsets_str.split("; "): cubes = [c.split(" ") for c in s.split(", ")] subsets.append({c[1]: int(c[0]) for c in cubes}) @@ -1,3 +1,4 @@ +# pyright: strict import re from collections import defaultdict from collections.abc import Iterator @@ -1,6 +1,8 @@ +# pyright: strict from dataclasses import dataclass from functools import cache from sys import stdin +from typing import Type @dataclass(frozen=True) @@ -14,7 +16,7 @@ class Card: return len(self.winning & self.have) @classmethod - def from_str(cls, s: str): + def from_str[T](cls: Type[T], s: str) -> T: card, rest = s.split(": ") _, card_id = card.split() winning, have = rest.split(" | ") |