Pyupgrade to Python 3.9 (#4718)

* Pyupgrade to Python 3.9

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2021-09-07 13:37:03 +02:00
committed by GitHub
parent 5d5831bdd0
commit cecf43d648
142 changed files with 523 additions and 530 deletions

View File

@ -12,8 +12,9 @@ There are other several other algorithms for the convex hull problem
which have not been implemented here, yet.
"""
from __future__ import annotations
from typing import Iterable, List, Set, Union
from typing import Iterable
class Point:
@ -84,8 +85,8 @@ class Point:
def _construct_points(
list_of_tuples: Union[List[Point], List[List[float]], Iterable[List[float]]]
) -> List[Point]:
list_of_tuples: list[Point] | list[list[float]] | Iterable[list[float]],
) -> list[Point]:
"""
constructs a list of points from an array-like object of numbers
@ -114,7 +115,7 @@ def _construct_points(
[]
"""
points: List[Point] = []
points: list[Point] = []
if list_of_tuples:
for p in list_of_tuples:
if isinstance(p, Point):
@ -130,7 +131,7 @@ def _construct_points(
return points
def _validate_input(points: Union[List[Point], List[List[float]]]) -> List[Point]:
def _validate_input(points: list[Point] | list[list[float]]) -> list[Point]:
"""
validates an input instance before a convex-hull algorithms uses it
@ -218,7 +219,7 @@ def _det(a: Point, b: Point, c: Point) -> float:
return det
def convex_hull_bf(points: List[Point]) -> List[Point]:
def convex_hull_bf(points: list[Point]) -> list[Point]:
"""
Constructs the convex hull of a set of 2D points using a brute force algorithm.
The algorithm basically considers all combinations of points (i, j) and uses the
@ -291,7 +292,7 @@ def convex_hull_bf(points: List[Point]) -> List[Point]:
return sorted(convex_set)
def convex_hull_recursive(points: List[Point]) -> List[Point]:
def convex_hull_recursive(points: list[Point]) -> list[Point]:
"""
Constructs the convex hull of a set of 2D points using a divide-and-conquer strategy
The algorithm exploits the geometric properties of the problem by repeatedly
@ -362,7 +363,7 @@ def convex_hull_recursive(points: List[Point]) -> List[Point]:
def _construct_hull(
points: List[Point], left: Point, right: Point, convex_set: Set[Point]
points: list[Point], left: Point, right: Point, convex_set: set[Point]
) -> None:
"""
@ -405,7 +406,7 @@ def _construct_hull(
_construct_hull(candidate_points, extreme_point, right, convex_set)
def convex_hull_melkman(points: List[Point]) -> List[Point]:
def convex_hull_melkman(points: list[Point]) -> list[Point]:
"""
Constructs the convex hull of a set of 2D points using the melkman algorithm.
The algorithm works by iteratively inserting points of a simple polygonal chain

View File

@ -8,8 +8,9 @@ This is a divide and conquer algorithm that can find a solution in O(n) time.
For more information of this algorithm:
https://web.stanford.edu/class/archive/cs/cs161/cs161.1138/lectures/08/Small08.pdf
"""
from __future__ import annotations
from random import choice
from typing import List
def random_pivot(lst):
@ -21,7 +22,7 @@ def random_pivot(lst):
return choice(lst)
def kth_number(lst: List[int], k: int) -> int:
def kth_number(lst: list[int], k: int) -> int:
"""
Return the kth smallest number in lst.
>>> kth_number([2, 1, 3, 4, 5], 3)

View File

@ -1,7 +1,7 @@
from typing import List
from __future__ import annotations
def merge(left_half: List, right_half: List) -> List:
def merge(left_half: list, right_half: list) -> list:
"""Helper function for mergesort.
>>> left_half = [-2]
@ -57,7 +57,7 @@ def merge(left_half: List, right_half: List) -> List:
return sorted_array
def merge_sort(array: List) -> List:
def merge_sort(array: list) -> list:
"""Returns a list of sorted array elements using merge sort.
>>> from random import shuffle

View File

@ -7,10 +7,10 @@ to find the maximum of the array.
(From Kleinberg and Tardos. Algorithm Design.
Addison Wesley 2006: Chapter 5 Solved Exercise 1)
"""
from typing import List
from __future__ import annotations
def peak(lst: List[int]) -> int:
def peak(lst: list[int]) -> int:
"""
Return the peak value of `lst`.
>>> peak([1, 2, 3, 4, 5, 4, 3, 2, 1])