From 58a01f120a597d8a2c89c7f2b88dd2408273ebfd Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 9 May 2023 14:44:52 -0700 Subject: [PATCH 1/4] Add more __slots__ --- arcade/gui/property.py | 20 ++++++++++++++++---- arcade/paths.py | 25 ++++++++++++++++++++++++- arcade/scene.py | 7 ++++++- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/arcade/gui/property.py b/arcade/gui/property.py index f4003e735..83beff2ed 100644 --- a/arcade/gui/property.py +++ b/arcade/gui/property.py @@ -9,7 +9,7 @@ class _Obs: Internal holder for Property value and change listeners """ - __slots__ = "value", "listeners" + __slots__ = ("value", "listeners") def __init__(self): self.value = None @@ -28,7 +28,7 @@ class Property: :param default_factory: A callable which returns the default value. Will be called with the property and the instance """ - __slots__ = "name", "default_factory", "obs" + __slots__ = ("name", "default_factory", "obs") name: str def __init__(self, default=None, default_factory=None): @@ -115,7 +115,13 @@ class MyObject: class _ObservableDict(dict): - # Internal class to observe changes inside a native python dict. + """Internal class to observe changes inside a native python dict.""" + + __slots__ = ( + "prop", + "obj" + ) + def __init__(self, prop: Property, instance, *largs): self.prop: Property = prop self.obj = ref(instance) @@ -170,7 +176,13 @@ def set(self, instance, value: dict): class _ObservableList(list): - # Internal class to observe changes inside a native python list. + """Internal class to observe changes inside a native python list.""" + + __slots__ = ( + "prop", + "obj" + ) + def __init__(self, prop: Property, instance, *largs): self.prop: Property = prop self.obj = ref(instance) diff --git a/arcade/paths.py b/arcade/paths.py index 5a4c1d4bb..21940e5c2 100644 --- a/arcade/paths.py +++ b/arcade/paths.py @@ -45,7 +45,16 @@ def _heuristic(start: Point, goal: Point): class _AStarGraph(object): - # Define a class board like grid with two barriers + """Define a class board like grid with two barriers""" + + __slots__ = ( + "barriers", + "left", + "right", + "top", + "bottom", + "movement_directions" + ) def __init__(self, barriers: Union[List, Tuple, Set], left: int, @@ -92,6 +101,7 @@ def move_cost(self, a: Point, b: Point): def _AStarSearch(start: Point, end: Point, graph: _AStarGraph) -> Optional[List[Point]]: + """An AStarSearch Algorithm for pathfinding""" G = {} # Actual movement cost to each position from the start position F = {} # Estimated movement cost of start to end going via this position @@ -176,6 +186,19 @@ class AStarBarrierList: :param int bottom: Bottom of playing field :param int top: Top of playing field """ + + __slots__ = ( + "grid_size", + "bottom", + "top", + "left", + "right", + "bottom", + "moving_sprite", + "blocking_sprites", + "barrier_list" + ) + def __init__(self, moving_sprite: Sprite, blocking_sprites: SpriteList, diff --git a/arcade/scene.py b/arcade/scene.py index 98e0c93a1..fa1633262 100644 --- a/arcade/scene.py +++ b/arcade/scene.py @@ -22,9 +22,14 @@ class Scene: Class that represents a `scene` object. Most games will use Scenes to render their Sprites. For examples on how to use this class, see: https://api.arcade.academy/en/latest/tutorials/views/index.html - """ + __slots__ = ( + "_sprite_lists", + "_name_mapping", + + ) + def __init__(self) -> None: self._sprite_lists: List[SpriteList] = [] self._name_mapping: Dict[str, SpriteList] = {} From 15a96e0e943d53d450dcab1a2cc5aad48564566a Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Wed, 10 May 2023 14:06:58 -0700 Subject: [PATCH 2/4] Update scene.py --- arcade/scene.py | 1 - 1 file changed, 1 deletion(-) diff --git a/arcade/scene.py b/arcade/scene.py index fa1633262..5e5b7b5a4 100644 --- a/arcade/scene.py +++ b/arcade/scene.py @@ -27,7 +27,6 @@ class Scene: __slots__ = ( "_sprite_lists", "_name_mapping", - ) def __init__(self) -> None: From f0e36bc858e15d342b3640dd05f9af413577d580 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sun, 28 May 2023 08:32:45 -0700 Subject: [PATCH 3/4] Remove __slots__ from scene --- arcade/scene.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arcade/scene.py b/arcade/scene.py index 5e5b7b5a4..a821e8464 100644 --- a/arcade/scene.py +++ b/arcade/scene.py @@ -24,11 +24,6 @@ class Scene: https://api.arcade.academy/en/latest/tutorials/views/index.html """ - __slots__ = ( - "_sprite_lists", - "_name_mapping", - ) - def __init__(self) -> None: self._sprite_lists: List[SpriteList] = [] self._name_mapping: Dict[str, SpriteList] = {} From ef64d2f746ec60a2c714ef8257905d698725f103 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Mon, 11 Sep 2023 17:14:27 +0200 Subject: [PATCH 4/4] Update paths.py --- arcade/paths.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/arcade/paths.py b/arcade/paths.py index 566f4223e..f6b09fba1 100644 --- a/arcade/paths.py +++ b/arcade/paths.py @@ -74,16 +74,6 @@ class _AStarGraph(object): :param int bottom: Far bottom side y value :param int top: Far top side y value """ - - __slots__ = ( - "barriers", - "left", - "right", - "top", - "bottom", - "movement_directions" - ) - def __init__(self, barriers: Union[List, Tuple, Set], left: int, right: int, @@ -246,19 +236,6 @@ class AStarBarrierList: :param int top: Top of playing field :param Optional[Set] barrier_list: SpriteList of barriers to use in _AStarSearch, None if not recalculated """ - - __slots__ = ( - "grid_size", - "bottom", - "top", - "left", - "right", - "bottom", - "moving_sprite", - "blocking_sprites", - "barrier_list" - ) - def __init__(self, moving_sprite: Sprite, blocking_sprites: SpriteList,