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

Python 3.13 #133

Merged
merged 4 commits into from
Dec 18, 2024
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bullseye
FROM mcr.microsoft.com/devcontainers/python:1-3.13-bullseye

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"containerEnv": {
"UV_CACHE_DIR": "${containerWorkspaceFolder}/.uv/cache",
"UV_TOOL_DIR": "${containerWorkspaceFolder}/.uv/tools"
"UV_TOOL_DIR": "${containerWorkspaceFolder}/.uv/tools",
"PYTHON_HISTORY": "${containerWorkspaceFolder}/.python_history"
},
"updateContentCommand": "uv sync && uv run poe sync",
"portsAttributes": {
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/uv-project-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
- name: Setup python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
with:
python-version: 3.12
python-version: 3.13
- name: Install project dependencies
run: uv sync
shell: bash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ cython_debug/

/node_modules/
/.ruff_cache/
/.python_history
4 changes: 2 additions & 2 deletions adventofcode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import time
from enum import StrEnum
from typing import TYPE_CHECKING, Annotated, Any, TypeGuard, assert_never
from typing import TYPE_CHECKING, Annotated, Any, TypeIs, assert_never

import joblib
import typer
Expand Down Expand Up @@ -253,7 +253,7 @@ def __init__(self, result_type: type) -> None:
super().__init__(f"Invalid result type: {result_type}")


def is_valid_result_type(result: Any) -> TypeGuard[answers.AnswerType]: # noqa: ANN401
def is_valid_result_type(result: Any) -> TypeIs[answers.AnswerType]: # noqa: ANN401
return isinstance(result, int)


Expand Down
7 changes: 5 additions & 2 deletions adventofcode/tooling/map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import enum
from typing import TYPE_CHECKING, Literal, assert_never, overload
from typing import TYPE_CHECKING, Generic, Literal, TypeVar, assert_never, overload

from .coordinates import X, Y
from .directions import RotationDirection
Expand All @@ -25,7 +25,10 @@ class IterDirection(enum.Enum):
Columns = enum.auto()


class Map2d[Map2dDataType]:
Map2dDataType = TypeVar("Map2dDataType", default=str)


class Map2d(Generic[Map2dDataType]):
__slots__ = ("_br_x", "_br_y", "_height", "_sequence_data", "_width")

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion adventofcode/y2023/d11.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from adventofcode.tooling.map import Map2d


class _InputMap(Map2d[str]):
class _InputMap(Map2d):
def __init__(self, data: Iterable[str]) -> None:
super().__init__(list(data))

Expand Down
8 changes: 4 additions & 4 deletions adventofcode/y2023/d13.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from adventofcode.tooling.map import IterDirection, Map2d


def _parse_maps(input_str: str) -> Iterable[Map2d[str]]:
def _parse_maps(input_str: str) -> Iterable[Map2d]:
lines: list[list[str]] = []
for line in input_str.splitlines():
if not line:
Expand All @@ -31,7 +31,7 @@ def _compare_datas(


def _find_consecutive_rows_or_columns(
map_: Map2d[str],
map_: Map2d,
start_pos: int,
direction: IterDirection,
allowed_mismatches: int,
Expand Down Expand Up @@ -59,7 +59,7 @@ def _map_data_iter_to_data(d: tuple[int, str]) -> str:


def _check_if_datas_around_reflection_match(
map_: Map2d[str],
map_: Map2d,
pos_before_reflection: int,
direction: IterDirection,
allowed_mismatches: int,
Expand Down Expand Up @@ -105,7 +105,7 @@ def _check_if_datas_around_reflection_match(


def _find_reflection_line(
map_: Map2d[str], direction: IterDirection, required_mismatches: int = 0
map_: Map2d, direction: IterDirection, required_mismatches: int = 0
) -> int | None:
logging.debug(
"Searching for reflection with %d required mismatches", required_mismatches
Expand Down
12 changes: 6 additions & 6 deletions adventofcode/y2023/d14.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_logger = logging.getLogger(__name__)


def _calculate_load(map_: Map2d[str]) -> int:
def _calculate_load(map_: Map2d) -> int:
max_load = map_.height
return sum(
max_load - y
Expand Down Expand Up @@ -152,7 +152,7 @@ def _get_new_rock_coords(
return Coord2d(coord.y, x)


def _roll_rocks(map_: Map2d[str], direction: Dir) -> Map2d[str]:
def _roll_rocks(map_: Map2d, direction: Dir) -> Map2d:
lines: list[list[str]] = [["."] * map_.width for _ in range(map_.height)]
roller: _RollVertical | _RollHorizontal
match direction:
Expand Down Expand Up @@ -184,13 +184,13 @@ def p1(input_str: str) -> int:
return _calculate_load(_roll_rocks(map_, Dir.N))


def _perform_spin(map_: Map2d[str]) -> Map2d[str]:
def _perform_spin(map_: Map2d) -> Map2d:
for dir_ in (Dir.N, Dir.W, Dir.S, Dir.E):
map_ = _roll_rocks(map_, dir_)
return map_


def _get_rock_coords(map_: Map2d[str]) -> frozenset[tuple[int, int]]:
def _get_rock_coords(map_: Map2d) -> frozenset[tuple[int, int]]:
return frozenset(
(x, y) for y, x_iter in map_.iter_data() for x, sym in x_iter if sym == "O"
)
Expand All @@ -199,9 +199,9 @@ def _get_rock_coords(map_: Map2d[str]) -> frozenset[tuple[int, int]]:
def p2(input_str: str) -> int:
map_ = Map2d([list(line) for line in input_str.splitlines()])
_logger.debug("Initial map:\n%s", map_)
maps_after_spins: list[Map2d[str]] = []
maps_after_spins: list[Map2d] = []
seen_rock_coords: dict[frozenset[tuple[int, int]], int] = {}
final_map: Map2d[str] | None = None
final_map: Map2d | None = None
for i in range(1, 1_000_000_000 + 1):
map_ = _perform_spin(map_)
_logger.info("Done spinning %d", i)
Expand Down
4 changes: 2 additions & 2 deletions adventofcode/y2023/d16.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def add(


def _process_splitter_exit(
coord: Coord2d, dir_: Dir, map_: Map2d[str]
coord: Coord2d, dir_: Dir, map_: Map2d
) -> tuple[set[Coord2d], list[tuple[Coord2d, Dir]]]:
visited: set[Coord2d] = set()
next_splitter_exits: list[tuple[Coord2d, Dir]] = []
Expand Down Expand Up @@ -95,7 +95,7 @@ def _process_splitter_exit(
def _try_one_enter(
enter_coord: Coord2d,
enter_dir: Dir,
map_: Map2d[str],
map_: Map2d,
exit_cache: _SplitterExitCache,
) -> int:
visited: set[Coord2d] = set()
Expand Down
4 changes: 2 additions & 2 deletions adventofcode/y2023/d19.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Iterable, Mapping
from enum import Enum
from queue import Queue
from typing import Literal, NewType, TypeGuard, cast
from typing import Literal, NewType, TypeIs, cast

from attrs import define, frozen

Expand All @@ -18,7 +18,7 @@
_Part = NewType("_Part", Mapping[_Category, int])


def is_category(category: str) -> TypeGuard[_Category]:
def is_category(category: str) -> TypeIs[_Category]:
return category in _categories


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "adventofcode"
version = "0.1.0"
description = ""
readme = "README.md"
requires-python = ">=3.12"
requires-python = ">=3.13"
dependencies = [
"attrs ==24.3.0",
"typer ==0.15.1",
Expand Down
26 changes: 1 addition & 25 deletions uv.lock

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

Loading