Skip to content

Commit 5af8e74

Browse files
committed
fix linter errors
1 parent 21d7b50 commit 5af8e74

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from enum import Enum
44
from typing import Tuple, TypeAlias
55

6-
Numpy2DArray: TypeAlias = np.ndarray[Tuple[int, int], np.dtype[np.int_]]
7-
Numpy1DArray: TypeAlias = np.ndarray[np.dtype[np.int_]]
6+
Numpy3DArray: TypeAlias = np.ndarray[Tuple[int, int, int], np.dtype[np.int_]]
87

98
class Position:
109
x: int
@@ -14,7 +13,7 @@ def __init__(self, x: int, y: int):
1413
self.x = x
1514
self.y = y
1615

17-
def as_ndarray(self) -> Numpy1DArray:
16+
def as_ndarray(self) -> np.ndarray:
1817
return np.array([self.x, self.y])
1918

2019
def __add__(self, other):
@@ -49,11 +48,11 @@ class ObstacleArrangement(Enum):
4948

5049
class Grid:
5150
# Set in constructor
52-
grid_size: Numpy1DArray
53-
grid: Numpy2DArray
51+
grid_size: np.ndarray
52+
grid: Numpy3DArray
5453
obstacle_paths: list[list[Position]] = []
5554
# Obstacles will never occupy these points. Useful to avoid impossible scenarios
56-
obstacle_avoid_points = []
55+
obstacle_avoid_points: list[Position] = []
5756

5857
# Number of time steps in the simulation
5958
time_limit: int
@@ -63,7 +62,7 @@ class Grid:
6362

6463
def __init__(
6564
self,
66-
grid_size: Numpy1DArray,
65+
grid_size: np.ndarray,
6766
num_obstacles: int = 40,
6867
obstacle_avoid_points: list[Position] = [],
6968
obstacle_arrangement: ObstacleArrangement = ObstacleArrangement.RANDOM,

PathPlanning/TimeBasedPathPlanning/SpaceTimeAStar.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Reference: https://www.davidsilver.uk/wp-content/uploads/2020/03/coop-path-AIWisdom.pdf
66
"""
77

8-
from __future__ import annotations # For typehints of a class within itself
98
import numpy as np
109
import matplotlib.pyplot as plt
1110
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
@@ -17,6 +16,7 @@
1716
from collections.abc import Generator
1817
import random
1918
from functools import total_ordering
19+
from typing import Optional
2020

2121
# Seed randomness for reproducibility
2222
RANDOM_SEED = 50
@@ -42,10 +42,14 @@ def __init__(
4242
This is what is used to drive node expansion. The node with the lowest value is expanded next.
4343
This comparison prioritizes the node with the lowest cost-to-come (self.time) + cost-to-go (self.heuristic)
4444
"""
45-
def __lt__(self, other: Node):
45+
def __lt__(self, other: object):
46+
if not isinstance(other, Node):
47+
return NotImplementedError(f"Cannot compare Node with object of type: {type(other)}")
4648
return (self.time + self.heuristic) < (other.time + other.heuristic)
4749

48-
def __eq__(self, other: Node):
50+
def __eq__(self, other: object):
51+
if not isinstance(other, Node):
52+
return NotImplementedError(f"Cannot compare Node with object of type: {type(other)}")
4953
return self.position == other.position and self.time == other.time
5054

5155
def __repr__(self):
@@ -64,7 +68,7 @@ def __init__(self, path: list[Node]):
6468
"""
6569
Get the position of the path at a given time
6670
"""
67-
def get_position(self, time: int) -> Position:
71+
def get_position(self, time: int) -> Optional[Position]:
6872
return self.positions_at_time.get(time)
6973

7074
"""
@@ -91,12 +95,12 @@ def __init__(self, grid: Grid, start: Position, goal: Position):
9195
self.goal = goal
9296

9397
def plan(self, verbose: bool = False) -> NodePath:
94-
open_set = []
98+
open_set: list[Node] = []
9599
heapq.heappush(
96100
open_set, Node(self.start, 0, self.calculate_heuristic(self.start), -1)
97101
)
98102

99-
expanded_set = []
103+
expanded_set: list[Node] = []
100104
while open_set:
101105
expanded_node: Node = heapq.heappop(open_set)
102106
if verbose:

0 commit comments

Comments
 (0)