From 1686a02179d67f8790dcbd3841e84be2e69d0319 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Mon, 4 Dec 2023 14:12:39 +0000 Subject: strict typing --- 1.py | 1 + 2.py | 3 ++- 3.py | 1 + 4.py | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/1.py b/1.py index 024c501..1c52458 100644 --- a/1.py +++ b/1.py @@ -1,3 +1,4 @@ +# pyright: strict import re from itertools import chain from sys import stdin diff --git a/2.py b/2.py index e21b3a4..d9c4433 100644 --- a/2.py +++ b/2.py @@ -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}) diff --git a/3.py b/3.py index 8f5a8d3..eed75a3 100644 --- a/3.py +++ b/3.py @@ -1,3 +1,4 @@ +# pyright: strict import re from collections import defaultdict from collections.abc import Iterator diff --git a/4.py b/4.py index dfd7468..04f645f 100644 --- a/4.py +++ b/4.py @@ -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(" | ") -- cgit v1.2.3-54-g00ecf