davecom/ClassicComputerScienceProblemsInPython

Returned type should be int not float

Closed this issue · 1 comments

Hello there,
I think, you should modify the type hints, since the xdist and ydist are both integer, so sum of them is going to be integer too, right?

def manhattan_distance(goal: MazeLocation) -> Callable[[MazeLocation], float]:
def distance(ml: MazeLocation) -> float:
xdist: int = abs(ml.column - goal.column)
ydist: int = abs(ml.row - goal.row)
return (xdist + ydist)
return distance

Probably; we return float because we want consistency with Euclidean distance, and so that the type hints match with the heuristic parameter of astar(). The alternative is a float() conversion at the end of distance().

Thanks for pointing this out.