]> Untitled Git - axy/ft/pacman.git/commitdiff
Type cleanup
authorAxy <gilliardmarthey.axel@gmail.com>
Sat, 19 Sep 2026 14:27:33 +0000 (16:27 +0200)
committerAxy <gilliardmarthey.axel@gmail.com>
Sat, 19 Sep 2026 14:27:33 +0000 (16:27 +0200)
pyproject.toml
src/pacman/ecs/__init__.py
src/pacman/ecs/hierarchy.py
src/pacman/ecs/schedule.py
src/pacman/ecs/world.py

index c1a0c92a3ce2d035f3a2648e2358b221464cadf6..1375c27be3966058f5fd044c642d2c23d6b506ae 100644 (file)
@@ -28,7 +28,8 @@ build-backend = "uv_build"
 
 [tool.ruff]
 line-length = 79
-lint.select = ["E", "F", "UP", "B", "SIM", "I", "ARG", "N", "D", "ANN", "PYI"]
+#lint.select = ["E", "F", "UP", "B", "SIM", "I", "ARG", "N", "D", "ANN", "PYI"]
+lint.select = ["E", "F", "UP", "B", "SIM", "I", "ARG", "N", "ANN", "PYI"]
 
 [tool.ruff.lint.pydocstyle]
 convention = "google"
index e4a15e670c618d3d8406fa6dd7659d0697a969c4..1bee6e4e3e86f487673a8d64421e0308e4a26bd8 100644 (file)
@@ -1,22 +1,16 @@
-from collections.abc import Callable, Generator, Iterable
 from dataclasses import dataclass
 from pathlib import Path
-from time import time
-from typing import Any, Literal, cast, overload
 
 import pygame
 from pygame import Vector2, Vector3
 
 from pacman.ecs.hierarchy import (
-    Children,
     Parent,
     hierachy_plugins,
     traverse_hierarchy,
 )
 from pacman.ecs.schedule import (
     MainSchedule,
-    Schedule,
-    ScheduleLabel,
     StartupSchedule,
     SystemSet,
     UpdateSchedule,
@@ -161,9 +155,9 @@ class WiggleSprite:
 def move_sprites(world: World) -> None:
     import math
 
-    time = pygame.time.get_ticks() / 100
+    tick = pygame.time.get_ticks() / 100
     for coord, _ in world[tuple[Coord2D, WiggleSprite]]:
-        pos = max(time - coord.z * 0.3, 0.0)
+        pos = max(tick - coord.z * 0.3, 0.0)
         coord.y = 500.0 + math.sin(pos) * 30.0
 
 
@@ -174,9 +168,9 @@ class WiggleRoot:
 def move_root(world: World) -> None:
     import math
 
-    time = pygame.time.get_ticks() / 100
+    tick = pygame.time.get_ticks() / 100
     for coord, _ in world[tuple[Coord2D, WiggleRoot]]:
-        coord.x = 30.0 + math.cos(time) * 30.0
+        coord.x = 30.0 + math.cos(tick) * 30.0
 
 
 if __name__ == "__main__":
index d2f5d9369467bc88c57031bb2f6a51aa00c28b06..89bb8583ef5aaaf7824dfeb98105a92ab33963e4 100644 (file)
@@ -10,8 +10,7 @@ class Children:
 
     @property
     def children(self) -> Generator[Entity]:
-        for child in self._children:
-            yield child
+        yield from self._children
 
 
 __no_hook = False
@@ -21,7 +20,8 @@ def get_parents(world: World, entity: Entity) -> Generator[Entity]:
     """Generate parents of entity including self"""
     yield entity
     while Parent in world[entity]:
-        entity: Entity = world[entity][Parent]._parent
+        nxt: Entity = world[entity][Parent]._parent
+        entity = nxt
         yield entity
 
 
@@ -81,7 +81,6 @@ def parent_insert_hook(
 def parent_remove_hook(
     world: World, entity: Entity, component: Parent
 ) -> None:
-    global __no_hook
     if __no_hook:
         return
     world[component.parent][Children]._children.remove(entity)
@@ -101,7 +100,7 @@ def traverse_hierarchy[*T](
     params = sorted(
         get_args(query), key=lambda e: len(world._components.get(e, {}))
     )
-    work = []
+    work: list[Entity] = []
     for e in world.query(query, without=tuple[Parent, Children]):
         yield (None, e)
     for entity, children in world.query(
index dd15d01a30aa6d3b68b2845d757687edaf267ef8..d9742f46a57eb4162406b1a8017743d30a102031 100644 (file)
@@ -79,7 +79,7 @@ class Schedule[T]:
         pre: Iterable[T | SystemSet],
         post: Iterable[T | SystemSet],
         group: Iterable[SystemSet],
-    ):
+    ) -> None:
         def get_pre(e: T | SystemSet) -> T | DAGLabel:
             if isinstance(e, SystemSet):
                 return e._pre
index 28d090b0813f23a17097ed45591a941a0c3dc7c5..bdbf8c2adf6175ac96af5f55aacd3a4af8622ca4 100644 (file)
@@ -1,3 +1,4 @@
+import contextlib
 from collections.abc import Callable, Generator
 from dataclasses import dataclass
 from typing import Any, Literal, cast, get_args, overload
@@ -19,7 +20,7 @@ class Resource[T]:
     storage: type[T]
 
 
-class SkipSystem(Exception):
+class SkipSystemError(Exception):
     pass
 
 
@@ -125,12 +126,15 @@ class World:
 
     @overload
     def __getitem__[T](self, arg: Resource[T]) -> T: ...
+
     @overload
     def __getitem__[*T](
         self, arg: type[tuple[*T]]
     ) -> Generator[tuple[*T]]: ...
+
     @overload
     def __getitem__(self, arg: Entity) -> EntityThunk: ...
+
     def __getitem__(
         self,
         arg: Any,
@@ -143,8 +147,10 @@ class World:
 
     @overload
     def __setitem__[T](self, key: Resource[T], val: T) -> None: ...
+
     @overload
     def __setitem__[*T](self, key: Entity, val: tuple[*T]) -> None: ...
+
     def __setitem__(self, key: Any, val: Any) -> None:
         if isinstance(key, Entity) and isinstance(val, tuple):
             if key in self:
@@ -159,8 +165,10 @@ class World:
 
     @overload
     def __delitem__[T](self, key: Resource[T]) -> None: ...
+
     @overload
     def __delitem__(self, key: Entity) -> None: ...
+
     def __delitem__[T](self, key: Entity | Resource[T]) -> None:
         if isinstance(key, Entity):
             components = self._entities[key]
@@ -187,14 +195,12 @@ class World:
         if schedule not in self._schedules:
             return
         for system in self._schedules[schedule].traverse(self._run_cond):
-            try:
+            with contextlib.suppress(SkipSystemError):
                 system(self)
-            except SkipSystem:
-                pass
 
     def res_s[T](self, ty: type[T]) -> T:
         if Resource(ty) not in self:
-            raise SkipSystem()
+            raise SkipSystemError()
         return self[Resource(ty)]
 
     def run(
@@ -233,10 +239,13 @@ class World:
             d[ty] = hook
         else:
             old = d[ty]
-            d[ty] = lambda world, entity, component: (
-                old(world, entity, component),
-                hook(world, entity, component),
-            )[1]
+
+            def new(world: World, entity: Entity, component: T) -> None:
+                old(world, entity, component)
+                hook(world, entity, component)
+                pass
+
+            d[ty] = new
         return self
 
     def with_plugins(self, *plugins: Plugin) -> "World":
@@ -290,7 +299,7 @@ class Systems:
         )
         sched.add_ordering((label,), self._pre, self._post, self._in_set)
         if self._chain:
-            prev = ()
+            prev: tuple[SystemSet | System] | tuple[()] = ()
             for system in systems:
                 sched.add_ordering((system,), prev, (), (label,))
                 prev = (system,)