commit 8289191d3e83a217c8c5753c45920c4263151cd2
parent 36d24d478d058203fc16309340adbef75cc411ed
Author: gracefu <81774659+gracefuu@users.noreply.github.com>
Date: Tue, 22 Apr 2025 20:49:51 +0800
Remove useless helper (.setdefault already exists)
Diffstat:
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/make2/__init__.py b/make2/__init__.py
@@ -1,6 +1,4 @@
-from _typeshed import Self
import asyncio
-from asyncio import gather
from asyncio.futures import Future
from contextlib import asynccontextmanager
from contextvars import ContextVar
@@ -18,7 +16,6 @@ from typing import (
runtime_checkable,
)
import dataclasses
-import weakref
# Alias confusing names that clash with the build system
AIOTask = asyncio.Task
@@ -37,7 +34,7 @@ Factory: TypeAlias = Callable[[], CovT]
@runtime_checkable
class HashLike(Protocol):
def __hash__(self) -> int: ...
- def __eq__(self: Self, other: Self, /) -> bool: ...
+ def __eq__(self, other, /) -> bool: ...
@dataclasses.dataclass(frozen=True)
@@ -165,6 +162,12 @@ LazyFuture.none.fut.set_result(None)
CovT = TypeVar("CovT", covariant=True)
+class Unset: ...
+
+
+unset = Unset()
+
+
@dataclasses.dataclass(frozen=True)
class Task(Generic[CovT]):
"""
@@ -178,8 +181,20 @@ class Task(Generic[CovT]):
"""
key: TaskKey = dataclasses.field()
- value: LazyFuture[CovT] = dataclasses.field(repr=False, compare=False)
- hash: LazyFuture[HashLike] = dataclasses.field(repr=False, compare=False)
+ value: LazyFuture[CovT] = dataclasses.field(compare=False)
+ hash: LazyFuture[HashLike] = dataclasses.field(compare=False)
+
+
+@dataclasses.dataclass
+class TaskRun(Generic[CovT]):
+ """
+ A task run is a recording of how the task ran last time.
+ """
+
+ key: TaskKey = dataclasses.field()
+ deps: dict[TaskKey, "TaskRun"] = dataclasses.field(default_factory=dict)
+ value: CovT | Unset = dataclasses.field(default=unset)
+ hash: HashLike | Unset = dataclasses.field(default=unset)
"""
diff --git a/make3/rebuild.py b/make3/rebuild.py
@@ -10,13 +10,6 @@ rerun_changes_var: contextvars.ContextVar[list[tuple[Any, bytes]]] = (
)
-def get_or_set[T](dict_: dict[str, T], key: str, val: T) -> T:
- if key in dict_:
- return dict_[key]
- dict_[key] = val
- return val
-
-
def with_rerun_context(rerun_changes, f, /, *args, **kwargs):
rerun_changes_var.set(rerun_changes)
return f(*args, **kwargs)