From b75a7c77f89e55e1f2510b2eca9b4fd1a5d21ed8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 11 Jul 2022 10:19:52 +0200 Subject: [PATCH] pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0 (#6245) * pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0 * pre-commit run --all-files --- .pre-commit-config.yaml | 2 +- arithmetic_analysis/bisection.py | 2 +- arithmetic_analysis/intersection.py | 2 +- arithmetic_analysis/newton_method.py | 2 +- boolean_algebra/quine_mc_cluskey.py | 2 +- ciphers/playfair_cipher.py | 2 +- computer_vision/horn_schunck.py | 3 ++- data_structures/binary_tree/binary_search_tree_recursive.py | 2 +- data_structures/binary_tree/binary_tree_traversals.py | 3 ++- data_structures/binary_tree/non_recursive_segment_tree.py | 3 ++- data_structures/binary_tree/red_black_tree.py | 2 +- data_structures/heap/heap.py | 2 +- data_structures/heap/randomized_heap.py | 3 ++- data_structures/heap/skew_heap.py | 3 ++- data_structures/linked_list/circular_linked_list.py | 3 ++- data_structures/queue/double_ended_queue.py | 3 ++- data_structures/queue/linked_queue.py | 3 ++- divide_and_conquer/convex_hull.py | 2 +- fractals/julia_sets.py | 3 ++- graphs/prim.py | 2 +- linear_algebra/src/lib.py | 3 ++- machine_learning/linear_discriminant_analysis.py | 3 ++- maths/area_under_curve.py | 2 +- maths/euclidean_distance.py | 3 ++- maths/euler_method.py | 2 +- maths/euler_modified.py | 2 +- maths/line_length.py | 2 +- maths/monte_carlo.py | 2 +- maths/numerical_integration.py | 2 +- maths/polynomial_evaluation.py | 2 +- maths/prime_numbers.py | 2 +- other/davisb_putnamb_logemannb_loveland.py | 2 +- other/lfu_cache.py | 3 ++- other/lru_cache.py | 3 ++- project_euler/problem_010/sol2.py | 2 +- project_euler/problem_025/sol2.py | 2 +- project_euler/problem_101/sol1.py | 3 ++- project_euler/problem_107/sol1.py | 2 +- project_euler/problem_123/sol1.py | 2 +- scripts/build_directory_md.py | 2 +- web_programming/fetch_jobs.py | 2 +- 41 files changed, 56 insertions(+), 41 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90feb50ff..7ff745997 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: - --profile=black - repo: https://github.com/asottile/pyupgrade - rev: v2.34.0 + rev: v2.37.0 hooks: - id: pyupgrade args: diff --git a/arithmetic_analysis/bisection.py b/arithmetic_analysis/bisection.py index 1feb4a8cf..640913a7a 100644 --- a/arithmetic_analysis/bisection.py +++ b/arithmetic_analysis/bisection.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable def bisection(function: Callable[[float], float], a: float, b: float) -> float: diff --git a/arithmetic_analysis/intersection.py b/arithmetic_analysis/intersection.py index 9d4651144..49213dd05 100644 --- a/arithmetic_analysis/intersection.py +++ b/arithmetic_analysis/intersection.py @@ -1,5 +1,5 @@ import math -from typing import Callable +from collections.abc import Callable def intersection(function: Callable[[float], float], x0: float, x1: float) -> float: diff --git a/arithmetic_analysis/newton_method.py b/arithmetic_analysis/newton_method.py index f0cf4eaa6..c4018a0f2 100644 --- a/arithmetic_analysis/newton_method.py +++ b/arithmetic_analysis/newton_method.py @@ -1,7 +1,7 @@ """Newton's Method.""" # Newton's Method - https://en.wikipedia.org/wiki/Newton%27s_method -from typing import Callable +from collections.abc import Callable RealFunc = Callable[[float], float] # type alias for a real -> real function diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index fb23c8c2e..9aa9b10c8 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Sequence +from collections.abc import Sequence def compare_string(string1: str, string2: str) -> str: diff --git a/ciphers/playfair_cipher.py b/ciphers/playfair_cipher.py index 7c0ee5bd5..89aedb7af 100644 --- a/ciphers/playfair_cipher.py +++ b/ciphers/playfair_cipher.py @@ -1,6 +1,6 @@ import itertools import string -from typing import Generator, Iterable +from collections.abc import Generator, Iterable def chunker(seq: Iterable[str], size: int) -> Generator[tuple[str, ...], None, None]: diff --git a/computer_vision/horn_schunck.py b/computer_vision/horn_schunck.py index 1428487d0..2a153d06d 100644 --- a/computer_vision/horn_schunck.py +++ b/computer_vision/horn_schunck.py @@ -9,9 +9,10 @@ Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf """ +from typing import SupportsIndex + import numpy as np from scipy.ndimage.filters import convolve -from typing_extensions import SupportsIndex def warp( diff --git a/data_structures/binary_tree/binary_search_tree_recursive.py b/data_structures/binary_tree/binary_search_tree_recursive.py index 4bdf4e33d..0d0ac8fd1 100644 --- a/data_structures/binary_tree/binary_search_tree_recursive.py +++ b/data_structures/binary_tree/binary_search_tree_recursive.py @@ -10,7 +10,7 @@ python binary_search_tree_recursive.py from __future__ import annotations import unittest -from typing import Iterator +from collections.abc import Iterator class Node: diff --git a/data_structures/binary_tree/binary_tree_traversals.py b/data_structures/binary_tree/binary_tree_traversals.py index 9a6239391..378598bb0 100644 --- a/data_structures/binary_tree/binary_tree_traversals.py +++ b/data_structures/binary_tree/binary_tree_traversals.py @@ -2,8 +2,9 @@ from __future__ import annotations from collections import deque +from collections.abc import Sequence from dataclasses import dataclass -from typing import Any, Sequence +from typing import Any @dataclass diff --git a/data_structures/binary_tree/non_recursive_segment_tree.py b/data_structures/binary_tree/non_recursive_segment_tree.py index b04a6e5ca..c29adefff 100644 --- a/data_structures/binary_tree/non_recursive_segment_tree.py +++ b/data_structures/binary_tree/non_recursive_segment_tree.py @@ -37,7 +37,8 @@ https://www.geeksforgeeks.org/segment-tree-efficient-implementation/ """ from __future__ import annotations -from typing import Any, Callable, Generic, TypeVar +from collections.abc import Callable +from typing import Any, Generic, TypeVar T = TypeVar("T") diff --git a/data_structures/binary_tree/red_black_tree.py b/data_structures/binary_tree/red_black_tree.py index 35517f307..a9dbd699c 100644 --- a/data_structures/binary_tree/red_black_tree.py +++ b/data_structures/binary_tree/red_black_tree.py @@ -4,7 +4,7 @@ flake8 : passed """ from __future__ import annotations -from typing import Iterator +from collections.abc import Iterator class RedBlackTree: diff --git a/data_structures/heap/heap.py b/data_structures/heap/heap.py index 550439edd..4c19747ec 100644 --- a/data_structures/heap/heap.py +++ b/data_structures/heap/heap.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Iterable +from collections.abc import Iterable class Heap: diff --git a/data_structures/heap/randomized_heap.py b/data_structures/heap/randomized_heap.py index bab4ec1b3..c0f9888f8 100644 --- a/data_structures/heap/randomized_heap.py +++ b/data_structures/heap/randomized_heap.py @@ -3,7 +3,8 @@ from __future__ import annotations import random -from typing import Any, Generic, Iterable, TypeVar +from collections.abc import Iterable +from typing import Any, Generic, TypeVar T = TypeVar("T", bound=bool) diff --git a/data_structures/heap/skew_heap.py b/data_structures/heap/skew_heap.py index 16ddc5545..490db061d 100644 --- a/data_structures/heap/skew_heap.py +++ b/data_structures/heap/skew_heap.py @@ -2,7 +2,8 @@ from __future__ import annotations -from typing import Any, Generic, Iterable, Iterator, TypeVar +from collections.abc import Iterable, Iterator +from typing import Any, Generic, TypeVar T = TypeVar("T", bound=bool) diff --git a/data_structures/linked_list/circular_linked_list.py b/data_structures/linked_list/circular_linked_list.py index 121d934c6..6fec0a125 100644 --- a/data_structures/linked_list/circular_linked_list.py +++ b/data_structures/linked_list/circular_linked_list.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Any, Iterator +from collections.abc import Iterator +from typing import Any class Node: diff --git a/data_structures/queue/double_ended_queue.py b/data_structures/queue/double_ended_queue.py index a4658d997..1603e50bc 100644 --- a/data_structures/queue/double_ended_queue.py +++ b/data_structures/queue/double_ended_queue.py @@ -3,8 +3,9 @@ Implementation of double ended queue. """ from __future__ import annotations +from collections.abc import Iterable from dataclasses import dataclass -from typing import Any, Iterable +from typing import Any class Deque: diff --git a/data_structures/queue/linked_queue.py b/data_structures/queue/linked_queue.py index 21970e7df..c6e9f5390 100644 --- a/data_structures/queue/linked_queue.py +++ b/data_structures/queue/linked_queue.py @@ -1,7 +1,8 @@ """ A Queue using a linked list like structure """ from __future__ import annotations -from typing import Any, Iterator +from collections.abc import Iterator +from typing import Any class Node: diff --git a/divide_and_conquer/convex_hull.py b/divide_and_conquer/convex_hull.py index 63f8dbb20..72da11639 100644 --- a/divide_and_conquer/convex_hull.py +++ b/divide_and_conquer/convex_hull.py @@ -14,7 +14,7 @@ which have not been implemented here, yet. """ from __future__ import annotations -from typing import Iterable +from collections.abc import Iterable class Point: diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 0168a0153..f27394385 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -22,7 +22,8 @@ Remark: Some overflow runtime warnings are suppressed. This is because of the """ import warnings -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import numpy from matplotlib import pyplot diff --git a/graphs/prim.py b/graphs/prim.py index 70329da7e..55d0fbfa8 100644 --- a/graphs/prim.py +++ b/graphs/prim.py @@ -7,7 +7,7 @@ import heapq as hq import math -from typing import Iterator +from collections.abc import Iterator class Vertex: diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index 2bfcea7f8..b9791c860 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -22,7 +22,8 @@ from __future__ import annotations import math import random -from typing import Collection, overload +from collections.abc import Collection +from typing import overload class Vector: diff --git a/machine_learning/linear_discriminant_analysis.py b/machine_learning/linear_discriminant_analysis.py index 18553a77a..9ef42ed19 100644 --- a/machine_learning/linear_discriminant_analysis.py +++ b/machine_learning/linear_discriminant_analysis.py @@ -42,10 +42,11 @@ Author: @EverLookNeverSee """ +from collections.abc import Callable from math import log from os import name, system from random import gauss, seed -from typing import Callable, TypeVar +from typing import TypeVar # Make a training dataset drawn from a gaussian distribution diff --git a/maths/area_under_curve.py b/maths/area_under_curve.py index 6fb3a7c98..d345398b4 100644 --- a/maths/area_under_curve.py +++ b/maths/area_under_curve.py @@ -3,7 +3,7 @@ Approximates the area under the curve using the trapezoidal rule """ from __future__ import annotations -from typing import Callable +from collections.abc import Callable def trapezoidal_area( diff --git a/maths/euclidean_distance.py b/maths/euclidean_distance.py index a20781613..22012e92c 100644 --- a/maths/euclidean_distance.py +++ b/maths/euclidean_distance.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Iterable, Union +from collections.abc import Iterable +from typing import Union import numpy as np diff --git a/maths/euler_method.py b/maths/euler_method.py index 155ef28d1..af7eecb2f 100644 --- a/maths/euler_method.py +++ b/maths/euler_method.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable import numpy as np diff --git a/maths/euler_modified.py b/maths/euler_modified.py index 7c76a0ee0..5659fa063 100644 --- a/maths/euler_modified.py +++ b/maths/euler_modified.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable import numpy as np diff --git a/maths/line_length.py b/maths/line_length.py index c4d986279..ad12a816b 100644 --- a/maths/line_length.py +++ b/maths/line_length.py @@ -1,7 +1,7 @@ from __future__ import annotations import math -from typing import Callable +from collections.abc import Callable def line_length( diff --git a/maths/monte_carlo.py b/maths/monte_carlo.py index efb6a01d5..c13b8d0a4 100644 --- a/maths/monte_carlo.py +++ b/maths/monte_carlo.py @@ -1,10 +1,10 @@ """ @author: MatteoRaso """ +from collections.abc import Callable from math import pi, sqrt from random import uniform from statistics import mean -from typing import Callable def pi_estimator(iterations: int): diff --git a/maths/numerical_integration.py b/maths/numerical_integration.py index cf2efce12..a2bfce5b9 100644 --- a/maths/numerical_integration.py +++ b/maths/numerical_integration.py @@ -3,7 +3,7 @@ Approximates the area under the curve using the trapezoidal rule """ from __future__ import annotations -from typing import Callable +from collections.abc import Callable def trapezoidal_area( diff --git a/maths/polynomial_evaluation.py b/maths/polynomial_evaluation.py index 4e4016e51..8ee82467e 100644 --- a/maths/polynomial_evaluation.py +++ b/maths/polynomial_evaluation.py @@ -1,4 +1,4 @@ -from typing import Sequence +from collections.abc import Sequence def evaluate_poly(poly: Sequence[float], x: float) -> float: diff --git a/maths/prime_numbers.py b/maths/prime_numbers.py index 183fbd393..7be4d3d95 100644 --- a/maths/prime_numbers.py +++ b/maths/prime_numbers.py @@ -1,5 +1,5 @@ import math -from typing import Generator +from collections.abc import Generator def slow_primes(max: int) -> Generator[int, None, None]: diff --git a/other/davisb_putnamb_logemannb_loveland.py b/other/davisb_putnamb_logemannb_loveland.py index 031f0dbed..88aefabc8 100644 --- a/other/davisb_putnamb_logemannb_loveland.py +++ b/other/davisb_putnamb_logemannb_loveland.py @@ -11,7 +11,7 @@ For more information about the algorithm: https://en.wikipedia.org/wiki/DPLL_alg from __future__ import annotations import random -from typing import Iterable +from collections.abc import Iterable class Clause: diff --git a/other/lfu_cache.py b/other/lfu_cache.py index e955973c9..072d00ab5 100644 --- a/other/lfu_cache.py +++ b/other/lfu_cache.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Callable, Generic, TypeVar +from collections.abc import Callable +from typing import Generic, TypeVar T = TypeVar("T") U = TypeVar("U") diff --git a/other/lru_cache.py b/other/lru_cache.py index 834ea52a9..b68ae0a8e 100644 --- a/other/lru_cache.py +++ b/other/lru_cache.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Callable, Generic, TypeVar +from collections.abc import Callable +from typing import Generic, TypeVar T = TypeVar("T") U = TypeVar("U") diff --git a/project_euler/problem_010/sol2.py b/project_euler/problem_010/sol2.py index 3a2f485dd..a288bb85f 100644 --- a/project_euler/problem_010/sol2.py +++ b/project_euler/problem_010/sol2.py @@ -11,8 +11,8 @@ References: - https://en.wikipedia.org/wiki/Prime_number """ import math +from collections.abc import Iterator from itertools import takewhile -from typing import Iterator def is_prime(number: int) -> bool: diff --git a/project_euler/problem_025/sol2.py b/project_euler/problem_025/sol2.py index b041afd98..6f49e89fb 100644 --- a/project_euler/problem_025/sol2.py +++ b/project_euler/problem_025/sol2.py @@ -23,7 +23,7 @@ The 12th term, F12, is the first term to contain three digits. What is the index of the first term in the Fibonacci sequence to contain 1000 digits? """ -from typing import Generator +from collections.abc import Generator def fibonacci_generator() -> Generator[int, None, None]: diff --git a/project_euler/problem_101/sol1.py b/project_euler/problem_101/sol1.py index 046788475..27438e086 100644 --- a/project_euler/problem_101/sol1.py +++ b/project_euler/problem_101/sol1.py @@ -43,7 +43,8 @@ Find the sum of FITs for the BOPs. """ from __future__ import annotations -from typing import Callable, Union +from collections.abc import Callable +from typing import Union Matrix = list[list[Union[float, int]]] diff --git a/project_euler/problem_107/sol1.py b/project_euler/problem_107/sol1.py index 6a411a114..048cf033d 100644 --- a/project_euler/problem_107/sol1.py +++ b/project_euler/problem_107/sol1.py @@ -30,7 +30,7 @@ Solution: from __future__ import annotations import os -from typing import Mapping +from collections.abc import Mapping EdgeT = tuple[int, int] diff --git a/project_euler/problem_123/sol1.py b/project_euler/problem_123/sol1.py index 919132227..f74cdd999 100644 --- a/project_euler/problem_123/sol1.py +++ b/project_euler/problem_123/sol1.py @@ -39,7 +39,7 @@ So it could be simplified as, """ from __future__ import annotations -from typing import Generator +from collections.abc import Generator def sieve() -> Generator[int, None, None]: diff --git a/scripts/build_directory_md.py b/scripts/build_directory_md.py index 71577fe6d..7572ce342 100755 --- a/scripts/build_directory_md.py +++ b/scripts/build_directory_md.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import os -from typing import Iterator +from collections.abc import Iterator def good_file_paths(top_dir: str = ".") -> Iterator[str]: diff --git a/web_programming/fetch_jobs.py b/web_programming/fetch_jobs.py index bb2171e1f..5af90a0bb 100644 --- a/web_programming/fetch_jobs.py +++ b/web_programming/fetch_jobs.py @@ -3,7 +3,7 @@ Scraping jobs given job title and location from indeed website """ from __future__ import annotations -from typing import Generator +from collections.abc import Generator import requests from bs4 import BeautifulSoup