GeezerVison is showing github.com — from __future__ import annotations (#2464) · jusing-es/Python@9200a2e
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .travis.yml +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,14 +14,14 @@ jobs: | 14 | 14 | - scripts/validate_filenames.py # no uppercase, no spaces, in a directory | 15 | 15 | - pip install -r requirements.txt # fast fail on black, flake8, validate_filenames | 16 | 16 | script: | 17 | | - - mypy --ignore-missing-imports . | | 17 | + - mypy --ignore-missing-imports . || true # https://github.com/python/mypy/issues/7907 | 18 | 18 | - pytest --doctest-modules --ignore=project_euler/ --durations=10 --cov-report=term-missing:skip-covered --cov=. . | 19 | 19 | - name: Project Euler | 20 | 20 | before_script: pip install pytest-cov | 21 | 21 | script: | 22 | 22 | - pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ | | 23 | +after_success: | | 24 | + - scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md | 23 | 25 | notifications: | 24 | 26 | webhooks: https://www.travisbuddy.com/ | 25 | 27 | on_success: never | 26 | | -after_success: | 27 | | - - scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md |
Collapse file Copy file name to clipboardExpand all lines: arithmetic_analysis/in_static_equilibrium.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | mypy : passed | 7 | 7 | """ | 8 | 8 |
| 9 | | -from typing import List | | 9 | +from __future__ import annotations | 10 | 10 |
| 11 | 11 | from numpy import array, cos, cross, radians, sin # type: ignore | 12 | 12 |
| 13 | 13 |
| 14 | 14 | def polar_force( | 15 | 15 | magnitude: float, angle: float, radian_mode: bool = False | 16 | | -) -> List[float]: | | 16 | +) -> list[float]: | 17 | 17 | """ | 18 | 18 | Resolves force along rectangular components. | 19 | 19 | (force, angle) => (force_x, force_y) | |
Collapse file Copy file name to clipboardExpand all lines: backtracking/coloring.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 |
| 6 | 6 | Wikipedia: https://en.wikipedia.org/wiki/Graph_coloring | 7 | 7 | """ | 8 | | -from typing import List | | 8 | +from __future__ import annotations | 9 | 9 |
| 10 | 10 |
| 11 | 11 | def valid_coloring( | 12 | | - neighbours: List[int], colored_vertices: List[int], color: int | | 12 | + neighbours: list[int], colored_vertices: list[int], color: int | 13 | 13 | ) -> bool: | 14 | 14 | """ | 15 | 15 | For each neighbour check if coloring constraint is satisfied | @@ -35,7 +35,7 @@ def valid_coloring( | 35 | 35 |
| 36 | 36 |
| 37 | 37 | def util_color( | 38 | | - graph: List[List[int]], max_colors: int, colored_vertices: List[int], index: int | | 38 | + graph: list[list[int]], max_colors: int, colored_vertices: list[int], index: int | 39 | 39 | ) -> bool: | 40 | 40 | """ | 41 | 41 | Pseudo-Code | @@ -86,7 +86,7 @@ def util_color( | 86 | 86 | return False | 87 | 87 |
| 88 | 88 |
| 89 | | -def color(graph: List[List[int]], max_colors: int) -> List[int]: | | 89 | +def color(graph: list[list[int]], max_colors: int) -> list[int]: | 90 | 90 | """ | 91 | 91 | Wrapper function to call subroutine called util_color | 92 | 92 | which will either return True or False. | |
Collapse file Copy file name to clipboardExpand all lines: backtracking/hamiltonian_cycle.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 |
| 7 | 7 | Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path | 8 | 8 | """ | 9 | | -from typing import List | | 9 | +from __future__ import annotations | 10 | 10 |
| 11 | 11 |
| 12 | 12 | def valid_connection( | 13 | | - graph: List[List[int]], next_ver: int, curr_ind: int, path: List[int] | | 13 | + graph: list[list[int]], next_ver: int, curr_ind: int, path: list[int] | 14 | 14 | ) -> bool: | 15 | 15 | """ | 16 | 16 | Checks whether it is possible to add next into path by validating 2 statements | @@ -47,7 +47,7 @@ def valid_connection( | 47 | 47 | return not any(vertex == next_ver for vertex in path) | 48 | 48 |
| 49 | 49 |
| 50 | | -def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int) -> bool: | | 50 | +def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int) -> bool: | 51 | 51 | """ | 52 | 52 | Pseudo-Code | 53 | 53 | Base Case: | @@ -108,7 +108,7 @@ def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int) | 108 | 108 | return False | 109 | 109 |
| 110 | 110 |
| 111 | | -def hamilton_cycle(graph: List[List[int]], start_index: int = 0) -> List[int]: | | 111 | +def hamilton_cycle(graph: list[list[int]], start_index: int = 0) -> list[int]: | 112 | 112 | r""" | 113 | 113 | Wrapper function to call subroutine called util_hamilton_cycle, | 114 | 114 | which will either return array of vertices indicating hamiltonian cycle | |
Collapse file Copy file name to clipboardExpand all lines: backtracking/knight_tour.py +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Knight Tour Intro: https://www.youtube.com/watch?v=ab_dY3dZFHM | 2 | 2 |
| 3 | | -from typing import List, Tuple | | 3 | +from __future__ import annotations | 4 | 4 |
| 5 | 5 |
| 6 | | -def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]: | | 6 | +def get_valid_pos(position: tuple[int], n: int) -> list[tuple[int]]: | 7 | 7 | """ | 8 | 8 | Find all the valid positions a knight can move to from the current position. | 9 | 9 |
| @@ -32,7 +32,7 @@ def get_valid_pos(position: Tuple[int], n: int) -> List[Tuple[int]]: | 32 | 32 | return permissible_positions | 33 | 33 |
| 34 | 34 |
| 35 | | -def is_complete(board: List[List[int]]) -> bool: | | 35 | +def is_complete(board: list[list[int]]) -> bool: | 36 | 36 | """ | 37 | 37 | Check if the board (matrix) has been completely filled with non-zero values. | 38 | 38 |
| @@ -46,7 +46,7 @@ def is_complete(board: List[List[int]]) -> bool: | 46 | 46 | return not any(elem == 0 for row in board for elem in row) | 47 | 47 |
| 48 | 48 |
| 49 | | -def open_knight_tour_helper(board: List[List[int]], pos: Tuple[int], curr: int) -> bool: | | 49 | +def open_knight_tour_helper(board: list[list[int]], pos: tuple[int], curr: int) -> bool: | 50 | 50 | """ | 51 | 51 | Helper function to solve knight tour problem. | 52 | 52 | """ | @@ -66,7 +66,7 @@ def open_knight_tour_helper(board: List[List[int]], pos: Tuple[int], curr: int) | 66 | 66 | return False | 67 | 67 |
| 68 | 68 |
| 69 | | -def open_knight_tour(n: int) -> List[List[int]]: | | 69 | +def open_knight_tour(n: int) -> list[list[int]]: | 70 | 70 | """ | 71 | 71 | Find the solution for the knight tour problem for a board of size n. Raises | 72 | 72 | ValueError if the tour cannot be performed for the given size. | |
Collapse file Copy file name to clipboardExpand all lines: backtracking/n_queens_math.py +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 75 | 75 | for another one or vice versa. | 76 | 76 |
| 77 | 77 | """ | 78 | | -from typing import List | | 78 | +from __future__ import annotations | 79 | 79 |
| 80 | 80 |
| 81 | 81 | def depth_first_search( | 82 | | - possible_board: List[int], | 83 | | - diagonal_right_collisions: List[int], | 84 | | - diagonal_left_collisions: List[int], | 85 | | - boards: List[List[str]], | | 82 | + possible_board: list[int], | | 83 | + diagonal_right_collisions: list[int], | | 84 | + diagonal_left_collisions: list[int], | | 85 | + boards: list[list[str]], | 86 | 86 | n: int, | 87 | 87 | ) -> None: | 88 | 88 | """ | |
Collapse file Copy file name to clipboardExpand all lines: cellular_automata/one_dimensional.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | https://mathworld.wolfram.com/ElementaryCellularAutomaton.html | 5 | 5 | """ | 6 | 6 |
| 7 | | -from typing import List | | 7 | +from __future__ import annotations | 8 | 8 |
| 9 | 9 | from PIL import Image | 10 | 10 |
| | 15 | 15 | # fmt: on | 16 | 16 |
| 17 | 17 |
| 18 | | -def format_ruleset(ruleset: int) -> List[int]: | | 18 | +def format_ruleset(ruleset: int) -> list[int]: | 19 | 19 | """ | 20 | 20 | >>> format_ruleset(11100) | 21 | 21 | [0, 0, 0, 1, 1, 1, 0, 0] | @@ -27,7 +27,7 @@ def format_ruleset(ruleset: int) -> List[int]: | 27 | 27 | return [int(c) for c in f"{ruleset:08}"[:8]] | 28 | 28 |
| 29 | 29 |
| 30 | | -def new_generation(cells: List[List[int]], rule: List[int], time: int) -> List[int]: | | 30 | +def new_generation(cells: list[list[int]], rule: list[int], time: int) -> list[int]: | 31 | 31 | population = len(cells[0]) # 31 | 32 | 32 | next_generation = [] | 33 | 33 | for i in range(population): | @@ -41,7 +41,7 @@ def new_generation(cells: List[List[int]], rule: List[int], time: int) -> List[i | 41 | 41 | return next_generation | 42 | 42 |
| 43 | 43 |
| 44 | | -def generate_image(cells: List[List[int]]) -> Image.Image: | | 44 | +def generate_image(cells: list[list[int]]) -> Image.Image: | 45 | 45 | """ | 46 | 46 | Convert the cells into a greyscale PIL.Image.Image and return it to the caller. | 47 | 47 | >>> from random import random | |
Collapse file Copy file name to clipboardExpand all lines: ciphers/rsa_factorization.py +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | More readable source: https://www.di-mgt.com.au/rsa_factorize_n.html | 8 | 8 | large number can take minutes to factor, therefore are not included in doctest. | 9 | 9 | """ | | 10 | +from __future__ import annotations | | 11 | + | 10 | 12 | import math | 11 | 13 | import random | 12 | | -from typing import List | 13 | 14 |
| 14 | 15 |
| 15 | | -def rsafactor(d: int, e: int, N: int) -> List[int]: | | 16 | +def rsafactor(d: int, e: int, N: int) -> list[int]: | 16 | 17 | """ | 17 | 18 | This function returns the factors of N, where p*q=N | 18 | 19 | Return: [p, q] | |
Collapse file Copy file name to clipboardExpand all lines: compression/burrows_wheeler.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | original character. The BWT is thus a "free" method of improving the efficiency | 11 | 11 | of text compression algorithms, costing only some extra computation. | 12 | 12 | """ | 13 | | -from typing import Dict, List | | 13 | +from __future__ import annotations | 14 | 14 |
| 15 | 15 |
| 16 | | -def all_rotations(s: str) -> List[str]: | | 16 | +def all_rotations(s: str) -> list[str]: | 17 | 17 | """ | 18 | 18 | :param s: The string that will be rotated len(s) times. | 19 | 19 | :return: A list with the rotations. | @@ -43,7 +43,7 @@ def all_rotations(s: str) -> List[str]: | 43 | 43 | return [s[i:] + s[:i] for i in range(len(s))] | 44 | 44 |
| 45 | 45 |
| 46 | | -def bwt_transform(s: str) -> Dict: | | 46 | +def bwt_transform(s: str) -> dict: | 47 | 47 | """ | 48 | 48 | :param s: The string that will be used at bwt algorithm | 49 | 49 | :return: the string composed of the last char of each row of the ordered | |
Collapse file Copy file name to clipboardExpand all lines: data_structures/binary_tree/lazy_segment_tree.py +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +from __future__ import annotations | | 2 | + | 1 | 3 | import math | 2 | | -from typing import List | 3 | 4 |
| 4 | 5 |
| 5 | 6 | class SegmentTree: | @@ -36,7 +37,7 @@ def right(self, idx: int) -> int: | 36 | 37 | return idx * 2 + 1 | 37 | 38 |
| 38 | 39 | def build( | 39 | | - self, idx: int, left_element: int, right_element: int, A: List[int] | | 40 | + self, idx: int, left_element: int, right_element: int, A: list[int] | 40 | 41 | ) -> None: | 41 | 42 | if left_element == right_element: | 42 | 43 | self.segment_tree[idx] = A[left_element - 1] | |
|