from __future__ import annotations (#2464)

* from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2020-09-23 13:30:13 +02:00
committed by GitHub
parent 6e6a49d19f
commit 9200a2e543
72 changed files with 275 additions and 250 deletions

View File

@@ -5,11 +5,11 @@
Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring
"""
from typing import List
from __future__ import annotations
def valid_coloring(
neighbours: List[int], colored_vertices: List[int], color: int
neighbours: list[int], colored_vertices: list[int], color: int
) -> bool:
"""
For each neighbour check if coloring constraint is satisfied
@@ -35,7 +35,7 @@ def valid_coloring(
def util_color(
graph: List[List[int]], max_colors: int, colored_vertices: List[int], index: int
graph: list[list[int]], max_colors: int, colored_vertices: list[int], index: int
) -> bool:
"""
Pseudo-Code
@@ -86,7 +86,7 @@ def util_color(
return False
def color(graph: List[List[int]], max_colors: int) -> List[int]:
def color(graph: list[list[int]], max_colors: int) -> list[int]:
"""
Wrapper function to call subroutine called util_color
which will either return True or False.

View File

@@ -6,11 +6,11 @@
Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
"""
from typing import List
from __future__ import annotations
def valid_connection(
graph: List[List[int]], next_ver: int, curr_ind: int, path: List[int]
graph: list[list[int]], next_ver: int, curr_ind: int, path: list[int]
) -> bool:
"""
Checks whether it is possible to add next into path by validating 2 statements
@@ -47,7 +47,7 @@ def valid_connection(
return not any(vertex == next_ver for vertex in path)
def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int) -> bool:
def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int) -> bool:
"""
Pseudo-Code
Base Case:
@@ -108,7 +108,7 @@ def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int)
return False
def hamilton_cycle(graph: List[List[int]], start_index: int = 0) -> List[int]:
def hamilton_cycle(graph: list[list[int]], start_index: int = 0) -> list[int]:
r"""
Wrapper function to call subroutine called util_hamilton_cycle,
which will either return array of vertices indicating hamiltonian cycle

View File

@@ -1,9 +1,9 @@
# Knight Tour Intro: https://www.youtube.com/watch?v=ab_dY3dZFHM
from typing import List, Tuple
from __future__ import annotations
def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]:
def get_valid_pos(position: tuple[int], n: int) -> list[tuple[int]]:
"""
Find all the valid positions a knight can move to from the current position.
@@ -32,7 +32,7 @@ def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]:
return permissible_positions
def is_complete(board: List[List[int]]) -> bool:
def is_complete(board: list[list[int]]) -> bool:
"""
Check if the board (matrix) has been completely filled with non-zero values.
@@ -46,7 +46,7 @@ def is_complete(board: List[List[int]]) -> bool:
return not any(elem == 0 for row in board for elem in row)
def open_knight_tour_helper(board: List[List[int]], pos: Tuple[int], curr: int) -> bool:
def open_knight_tour_helper(board: list[list[int]], pos: tuple[int], curr: int) -> bool:
"""
Helper function to solve knight tour problem.
"""
@@ -66,7 +66,7 @@ def open_knight_tour_helper(board: List[List[int]], pos: Tuple[int], curr: int)
return False
def open_knight_tour(n: int) -> List[List[int]]:
def open_knight_tour(n: int) -> list[list[int]]:
"""
Find the solution for the knight tour problem for a board of size n. Raises
ValueError if the tour cannot be performed for the given size.

View File

@@ -75,14 +75,14 @@ Applying this two formulas we can check if a queen in some position is being att
for another one or vice versa.
"""
from typing import List
from __future__ import annotations
def depth_first_search(
possible_board: List[int],
diagonal_right_collisions: List[int],
diagonal_left_collisions: List[int],
boards: List[List[str]],
possible_board: list[int],
diagonal_right_collisions: list[int],
diagonal_left_collisions: list[int],
boards: list[list[str]],
n: int,
) -> None:
"""