Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps-dev): bump mypy from 1.4.1 to 1.5.1 #245

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ black = "^23.7.0"
pre-commit = "^3.3.3"
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
mypy = "^1.4"
mypy = "^1.5"

[tool.poetry.plugins."adventofcode.user"]
cj81499 = "aoc_cj:solve"
Expand Down Expand Up @@ -60,6 +60,7 @@ xfail_strict=true

[tool.mypy]
strict = true
enable_error_code = ["explicit-override"]
# TODO: type check tests too
exclude = [
'^tests\/aoc2015\/',
Expand Down
4 changes: 4 additions & 0 deletions src/aoc_cj/aoc2021/day16.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from more_itertools import ichunked, take
from more_itertools.more import peekable
from typing_extensions import override

Binary = Literal[0, 1]

Expand All @@ -30,6 +31,7 @@ class LiteralValuePacket(Packet):
def __post_init__(self) -> None:
assert self.type_id == 4

@override
def evaluate(self) -> int:
return self.value

Expand All @@ -38,9 +40,11 @@ def evaluate(self) -> int:
class OperatorPacket(Packet):
children: Sequence[Packet]

@override
def version_sum(self) -> int:
return super().version_sum() + sum(c.version_sum() for c in self.children)

@override
def evaluate(self) -> int:
# Packets with type ID 0 are sum packets - their value is the sum of the values of their sub-packets. If they only have a single sub-packet, their value is the value of the sub-packet.
if self.type_id == 0:
Expand Down
11 changes: 11 additions & 0 deletions src/aoc_cj/aoc2021/day18.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Optional

from more_itertools import peekable
from typing_extensions import override


@dataclasses.dataclass
Expand Down Expand Up @@ -69,9 +70,11 @@ def __post_init__(self) -> None:
self.left.parent = self
self.right.parent = self

@override
def magnitude(self) -> int:
return 3 * self.left.magnitude() + 2 * self.right.magnitude()

@override
def _explodable(self, depth: int = 0) -> Iterator["PairNode"]:
if depth > 4:
return # too deep
Expand All @@ -80,10 +83,12 @@ def _explodable(self, depth: int = 0) -> Iterator["PairNode"]:
yield self
yield from self.right._explodable(depth + 1)

@override
def _splitable(self) -> Iterator["ValueNode"]:
yield from self.left._splitable()
yield from self.right._splitable()

@override
def _in_order_traverse(self) -> Iterator[TreeNode]:
yield from self.left._in_order_traverse()
yield self
Expand Down Expand Up @@ -116,6 +121,7 @@ def explode(self) -> None:

self.replace_with(ValueNode(self.parent, 0))

@override
def __repr__(self) -> str:
return f"[{self.left},{self.right}]"

Expand All @@ -124,12 +130,15 @@ def __repr__(self) -> str:
class ValueNode(TreeNode):
value: int

@override
def magnitude(self) -> int:
return self.value

@override
def _explodable(self, depth: int = 0) -> Iterator[PairNode]:
yield from () # ValueNodes are never explodable

@override
def _splitable(self) -> Iterator["ValueNode"]:
if self.value >= 10:
yield self
Expand All @@ -145,9 +154,11 @@ def split(self) -> None:
elif p.right is self:
p.right = new_pair

@override
def _in_order_traverse(self) -> Iterator[TreeNode]:
yield self

@override
def __repr__(self) -> str:
return str(self.value)

Expand Down
3 changes: 3 additions & 0 deletions src/aoc_cj/aoc2022/day17.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import itertools
from collections.abc import Generator, Iterable, Iterator

from typing_extensions import override


class Rock:
def __init__(self, points: Iterable[complex]) -> None:
Expand All @@ -12,6 +14,7 @@ def __init__(self, points: Iterable[complex]) -> None:
self.highest_y = int(max(p.imag for p in self._points))
self.lowest_y = int(min(p.imag for p in self._points))

@override
def __str__(self) -> str:
return "\n".join(
"".join(
Expand Down
11 changes: 11 additions & 0 deletions src/aoc_cj/aoc2022/day21.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import enum
from typing import Callable, Optional, Union

from typing_extensions import override

IntFn = Callable[[int, int], int]

Monkeys = dict[str, Union[int, tuple[str, str, str]]]
Expand Down Expand Up @@ -73,12 +75,15 @@ def __init__(self, name: str, value: int) -> None:
super().__init__(name)
self.value = value

@override
def evaluate(self, _monkeys: dict[str, Monkey]) -> int:
return self.value

@override
def contains(self, name: str, monkeys: dict[str, Monkey]) -> bool:
return self.name == name

@override
def _solve_humn(self, monkeys: dict[str, Monkey], target: int) -> int:
assert self.name == HUMN
return target
Expand All @@ -94,9 +99,11 @@ def __init__(self, name: str, left: str, op: Operation, right: str) -> None:

self._resolved: Optional[ResolvedMonkey] = None

@override
def evaluate(self, monkeys: dict[str, Monkey]) -> int:
return self._resolve(monkeys).evaluate(monkeys)

@override
def contains(self, name: str, monkeys: dict[str, Monkey]) -> bool:
return self._resolve(monkeys).contains(name, monkeys)

Expand All @@ -113,6 +120,7 @@ def solve_humn(self, monkeys: dict[str, Monkey]) -> int:
# if this is the root monkey, we don't have a target value yet.
return monkey_containing_humn._solve_humn(monkeys, target=known_value)

@override
def _solve_humn(self, monkeys: dict[str, Monkey], target: int) -> int:
return self._resolve(monkeys)._solve_humn(monkeys, target)

Expand All @@ -132,14 +140,17 @@ def __init__(self, name: str, left: Monkey, op: Operation, right: Monkey) -> Non

self._contains_humn: Optional[bool] = None

@override
def evaluate(self, monkeys: dict[str, Monkey]) -> int:
return self.op.apply(self.left.evaluate(monkeys), self.right.evaluate(monkeys))

@override
def contains(self, name: str, monkeys: dict[str, Monkey]) -> bool:
if self._contains_humn is None:
self._contains_humn = self.left.contains(name, monkeys) or self.right.contains(name, monkeys)
return self._contains_humn

@override
def _solve_humn(self, monkeys: dict[str, Monkey], target: int) -> int:
# either left or right must contain HUMN
assert (left_contains_humn := self.left.contains(HUMN, monkeys)) ^ self.right.contains(HUMN, monkeys)
Expand Down