Skip to content

Commit 561366a

Browse files
committed
Mypy cleanup. Better List usages
1 parent ce9de09 commit 561366a

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

algorithms/hunt_and_kill.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def on(grid: Grid) -> Grid:
2020

2121
while current_cell is not None:
2222
unvisited_neighbors = \
23-
[neighbor for neighbor in current_cell.neighbors if len(neighbor.links) == 0] # type: ignore
23+
[neighbor for neighbor in current_cell.neighbors if len(neighbor.links) == 0]
2424

2525
if len(unvisited_neighbors) > 0:
2626
# as long as there are unvisited paths, walk them
27-
neighbor = cast(Cell, choice(unvisited_neighbors))
27+
neighbor = choice(unvisited_neighbors)
2828
current_cell.link(neighbor)
2929
current_cell = neighbor
3030
else:

algorithms/sidewinder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def on(grid: Grid) -> Grid:
2424
member = choice(run)
2525
if member.north:
2626
member.link(member.north)
27-
run = []
27+
run.clear()
2828
else:
2929
cell.link(cell.east)
3030
return grid

algorithms/wilson.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class Wilson:
1515

1616
@staticmethod
1717
def on(grid: Grid) -> Grid:
18-
unvisited = [] # Type: List[Cell]
18+
unvisited = []
1919
for cell in grid.each_cell():
2020
unvisited.append(cell)
2121

2222
first_cell = choice(unvisited)
23-
del unvisited[unvisited.index(first_cell)]
23+
unvisited.remove(first_cell)
2424

2525
while len(unvisited) > 0:
2626
# start a walk
@@ -39,6 +39,6 @@ def on(grid: Grid) -> Grid:
3939
# Passage carving once has found a valid path
4040
for index in range(len(path) - 1):
4141
path[index].link(path[index + 1])
42-
del unvisited[unvisited.index(path[index])]
42+
unvisited.remove(path[index])
4343

4444
return grid

base/cell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def links(self) -> List["Cell"]:
1818
return list(self._links.keys())
1919

2020
@property
21-
def neighbors(self) -> List[Optional["Cell"]]:
22-
neighbors_list = [] # type: List[Optional[Cell]]
21+
def neighbors(self) -> List["Cell"]:
22+
neighbors_list = [] # type: List[Cell]
2323
if self.north:
2424
neighbors_list.append(self.north)
2525
if self.south:
@@ -62,7 +62,7 @@ def linked_to(self, cell: "Cell") -> bool:
6262
@property
6363
def distances(self) -> Distances:
6464
distances = Distances(self)
65-
frontier = [self] # type: List[Cell]
65+
frontier = [self]
6666

6767
while len(frontier) > 0:
6868
new_frontier = []

base/grid.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def columns(self) -> int:
1818
def size(self) -> int:
1919
return self.rows * self.columns
2020

21+
@property
22+
def deadends(self) -> List[Cell]:
23+
deadends_list = []
24+
for cell in self.each_cell():
25+
if len(cell.links) == 1:
26+
deadends_list.append(cell)
27+
return deadends_list
28+
2129
def __init__(self, rows: int, columns: int) -> None:
2230
if rows is None or rows < 0:
2331
raise ValueError("Rows must be a positive integer")

demos/demo_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_renderer(available_renderers: List[str], default_renderer: str) -> Tuple
3030
if key == "--renderer":
3131
try:
3232
renderer_name = args.assignments[key][0]
33+
# Hacky but only method I know to get an alias of an imported module
3334
if renderer_name in available_renderers and renderer_name in globals():
3435
renderer = globals()[renderer_name]
3536
except ValueError as error:

0 commit comments

Comments
 (0)