[pre-commit.ci] pre-commit autoupdate -- ruff 2025 stable format (#12521)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.6...v0.9.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update maths/dual_number_automatic_differentiation.py

* Update maths/dual_number_automatic_differentiation.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update dual_number_automatic_differentiation.py

* Update dual_number_automatic_differentiation.py

* No <fin-streamer> tag with the specified data-test attribute found.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
pre-commit-ci[bot] 2025-01-13 21:52:12 +01:00 committed by GitHub
parent cfcc84edf7
commit 4fe50bc1fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 93 additions and 91 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus - id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6 rev: v0.9.1
hooks: hooks:
- id: ruff - id: ruff
- id: ruff-format - id: ruff-format

View File

@ -105,13 +105,13 @@ def base64_decode(encoded_data: str) -> bytes:
# Check if the encoded string contains non base64 characters # Check if the encoded string contains non base64 characters
if padding: if padding:
assert all( assert all(char in B64_CHARSET for char in encoded_data[:-padding]), (
char in B64_CHARSET for char in encoded_data[:-padding] "Invalid base64 character(s) found."
), "Invalid base64 character(s) found." )
else: else:
assert all( assert all(char in B64_CHARSET for char in encoded_data), (
char in B64_CHARSET for char in encoded_data "Invalid base64 character(s) found."
), "Invalid base64 character(s) found." )
# Check the padding # Check the padding
assert len(encoded_data) % 4 == 0 and padding < 3, "Incorrect padding" assert len(encoded_data) % 4 == 0 and padding < 3, "Incorrect padding"

View File

@ -225,7 +225,7 @@ def brute_force(input_string: str, alphabet: str | None = None) -> dict[int, str
if __name__ == "__main__": if __name__ == "__main__":
while True: while True:
print(f'\n{"-" * 10}\n Menu\n{"-" * 10}') print(f"\n{'-' * 10}\n Menu\n{'-' * 10}")
print(*["1.Encrypt", "2.Decrypt", "3.BruteForce", "4.Quit"], sep="\n") print(*["1.Encrypt", "2.Decrypt", "3.BruteForce", "4.Quit"], sep="\n")
# get user input # get user input

View File

@ -32,9 +32,9 @@ def is_prime(number: int) -> bool:
""" """
# precondition # precondition
assert isinstance(number, int) and ( assert isinstance(number, int) and (number >= 0), (
number >= 0 "'number' must been an int and positive"
), "'number' must been an int and positive" )
if 1 < number < 4: if 1 < number < 4:
# 2 and 3 are primes # 2 and 3 are primes

View File

@ -124,9 +124,9 @@ class MinHeap:
return len(self.heap) == 0 return len(self.heap) == 0
def decrease_key(self, node, new_value): def decrease_key(self, node, new_value):
assert ( assert self.heap[self.idx_of_element[node]].val > new_value, (
self.heap[self.idx_of_element[node]].val > new_value "newValue must be less that current value"
), "newValue must be less that current value" )
node.val = new_value node.val = new_value
self.heap_dict[node.name] = new_value self.heap_dict[node.name] = new_value
self.sift_up(self.idx_of_element[node]) self.sift_up(self.idx_of_element[node])

View File

@ -48,14 +48,14 @@ def test_build_kdtree(num_points, cube_size, num_dimensions, depth, expected_res
assert kdtree is not None, "Expected a KDNode, got None" assert kdtree is not None, "Expected a KDNode, got None"
# Check if root has correct dimensions # Check if root has correct dimensions
assert ( assert len(kdtree.point) == num_dimensions, (
len(kdtree.point) == num_dimensions f"Expected point dimension {num_dimensions}, got {len(kdtree.point)}"
), f"Expected point dimension {num_dimensions}, got {len(kdtree.point)}" )
# Check that the tree is balanced to some extent (simplistic check) # Check that the tree is balanced to some extent (simplistic check)
assert isinstance( assert isinstance(kdtree, KDNode), (
kdtree, KDNode f"Expected KDNode instance, got {type(kdtree)}"
), f"Expected KDNode instance, got {type(kdtree)}" )
def test_nearest_neighbour_search(): def test_nearest_neighbour_search():

View File

@ -22,18 +22,18 @@ class TestSuffixTree(unittest.TestCase):
patterns = ["ana", "ban", "na"] patterns = ["ana", "ban", "na"]
for pattern in patterns: for pattern in patterns:
with self.subTest(pattern=pattern): with self.subTest(pattern=pattern):
assert self.suffix_tree.search( assert self.suffix_tree.search(pattern), (
pattern f"Pattern '{pattern}' should be found."
), f"Pattern '{pattern}' should be found." )
def test_search_non_existing_patterns(self) -> None: def test_search_non_existing_patterns(self) -> None:
"""Test searching for patterns that do not exist in the suffix tree.""" """Test searching for patterns that do not exist in the suffix tree."""
patterns = ["xyz", "apple", "cat"] patterns = ["xyz", "apple", "cat"]
for pattern in patterns: for pattern in patterns:
with self.subTest(pattern=pattern): with self.subTest(pattern=pattern):
assert not self.suffix_tree.search( assert not self.suffix_tree.search(pattern), (
pattern f"Pattern '{pattern}' should not be found."
), f"Pattern '{pattern}' should not be found." )
def test_search_empty_pattern(self) -> None: def test_search_empty_pattern(self) -> None:
"""Test searching for an empty pattern.""" """Test searching for an empty pattern."""
@ -41,18 +41,18 @@ class TestSuffixTree(unittest.TestCase):
def test_search_full_text(self) -> None: def test_search_full_text(self) -> None:
"""Test searching for the full text.""" """Test searching for the full text."""
assert self.suffix_tree.search( assert self.suffix_tree.search(self.text), (
self.text "The full text should be found in the suffix tree."
), "The full text should be found in the suffix tree." )
def test_search_substrings(self) -> None: def test_search_substrings(self) -> None:
"""Test searching for substrings of the full text.""" """Test searching for substrings of the full text."""
substrings = ["ban", "ana", "a", "na"] substrings = ["ban", "ana", "a", "na"]
for substring in substrings: for substring in substrings:
with self.subTest(substring=substring): with self.subTest(substring=substring):
assert self.suffix_tree.search( assert self.suffix_tree.search(substring), (
substring f"Substring '{substring}' should be found."
), f"Substring '{substring}' should be found." )
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -25,9 +25,9 @@ def climb_stairs(number_of_steps: int) -> int:
... ...
AssertionError: number_of_steps needs to be positive integer, your input -7 AssertionError: number_of_steps needs to be positive integer, your input -7
""" """
assert ( assert isinstance(number_of_steps, int) and number_of_steps > 0, (
isinstance(number_of_steps, int) and number_of_steps > 0 f"number_of_steps needs to be positive integer, your input {number_of_steps}"
), f"number_of_steps needs to be positive integer, your input {number_of_steps}" )
if number_of_steps == 1: if number_of_steps == 1:
return 1 return 1
previous, current = 1, 1 previous, current = 1, 1

View File

@ -37,9 +37,9 @@ def list_of_submasks(mask: int) -> list[int]:
""" """
assert ( assert isinstance(mask, int) and mask > 0, (
isinstance(mask, int) and mask > 0 f"mask needs to be positive integer, your input {mask}"
), f"mask needs to be positive integer, your input {mask}" )
""" """
first submask iterated will be mask itself then operation will be performed first submask iterated will be mask itself then operation will be performed

View File

@ -17,10 +17,8 @@ class Dual:
self.duals = rank self.duals = rank
def __repr__(self): def __repr__(self):
return ( s = "+".join(f"{dual}E{n}" for n, dual in enumerate(self.duals, 1))
f"{self.real}+" return f"{self.real}+{s}"
f"{'+'.join(str(dual)+'E'+str(n+1)for n,dual in enumerate(self.duals))}"
)
def reduce(self): def reduce(self):
cur = self.duals.copy() cur = self.duals.copy()

View File

@ -43,4 +43,6 @@ if __name__ == "__main__":
testmod() testmod()
array = [randint(-1000, 1000) for i in range(100)] array = [randint(-1000, 1000) for i in range(100)]
k = randint(0, 110) k = randint(0, 110)
print(f"The maximum sum of {k} consecutive elements is {max_sum_in_array(array,k)}") print(
f"The maximum sum of {k} consecutive elements is {max_sum_in_array(array, k)}"
)

View File

@ -88,18 +88,18 @@ def simpson_integration(function, a: float, b: float, precision: int = 4) -> flo
AssertionError: precision should be positive integer your input : -1 AssertionError: precision should be positive integer your input : -1
""" """
assert callable( assert callable(function), (
function f"the function(object) passed should be callable your input : {function}"
), f"the function(object) passed should be callable your input : {function}" )
assert isinstance(a, (float, int)), f"a should be float or integer your input : {a}" assert isinstance(a, (float, int)), f"a should be float or integer your input : {a}"
assert isinstance(function(a), (float, int)), ( assert isinstance(function(a), (float, int)), (
"the function should return integer or float return type of your function, " "the function should return integer or float return type of your function, "
f"{type(a)}" f"{type(a)}"
) )
assert isinstance(b, (float, int)), f"b should be float or integer your input : {b}" assert isinstance(b, (float, int)), f"b should be float or integer your input : {b}"
assert ( assert isinstance(precision, int) and precision > 0, (
isinstance(precision, int) and precision > 0 f"precision should be positive integer your input : {precision}"
), f"precision should be positive integer your input : {precision}" )
# just applying the formula of simpson for approximate integration written in # just applying the formula of simpson for approximate integration written in
# mentioned article in first comment of this file and above this function # mentioned article in first comment of this file and above this function

View File

@ -73,12 +73,12 @@ class Test(unittest.TestCase):
def test_not_primes(self): def test_not_primes(self):
with pytest.raises(ValueError): with pytest.raises(ValueError):
is_prime(-19) is_prime(-19)
assert not is_prime( assert not is_prime(0), (
0 "Zero doesn't have any positive factors, primes must have exactly two."
), "Zero doesn't have any positive factors, primes must have exactly two." )
assert not is_prime( assert not is_prime(1), (
1 "One only has 1 positive factor, primes must have exactly two."
), "One only has 1 positive factor, primes must have exactly two." )
assert not is_prime(2 * 2) assert not is_prime(2 * 2)
assert not is_prime(2 * 3) assert not is_prime(2 * 3)
assert not is_prime(3 * 3) assert not is_prime(3 * 3)

View File

@ -66,9 +66,9 @@ def is_prime(number: int) -> bool:
""" """
# precondition # precondition
assert isinstance(number, int) and ( assert isinstance(number, int) and (number >= 0), (
number >= 0 "'number' must been an int and positive"
), "'number' must been an int and positive" )
status = True status = True
@ -254,9 +254,9 @@ def greatest_prime_factor(number):
""" """
# precondition # precondition
assert isinstance(number, int) and ( assert isinstance(number, int) and (number >= 0), (
number >= 0 "'number' must been an int and >= 0"
), "'number' must been an int and >= 0" )
ans = 0 ans = 0
@ -296,9 +296,9 @@ def smallest_prime_factor(number):
""" """
# precondition # precondition
assert isinstance(number, int) and ( assert isinstance(number, int) and (number >= 0), (
number >= 0 "'number' must been an int and >= 0"
), "'number' must been an int and >= 0" )
ans = 0 ans = 0
@ -399,9 +399,9 @@ def goldbach(number):
""" """
# precondition # precondition
assert ( assert isinstance(number, int) and (number > 2) and is_even(number), (
isinstance(number, int) and (number > 2) and is_even(number) "'number' must been an int, even and > 2"
), "'number' must been an int, even and > 2" )
ans = [] # this list will returned ans = [] # this list will returned
@ -525,9 +525,9 @@ def kg_v(number1, number2):
done.append(n) done.append(n)
# precondition # precondition
assert isinstance(ans, int) and ( assert isinstance(ans, int) and (ans >= 0), (
ans >= 0 "'ans' must been from type int and positive"
), "'ans' must been from type int and positive" )
return ans return ans
@ -574,9 +574,9 @@ def get_prime(n):
ans += 1 ans += 1
# precondition # precondition
assert isinstance(ans, int) and is_prime( assert isinstance(ans, int) and is_prime(ans), (
ans "'ans' must been a prime number and from type int"
), "'ans' must been a prime number and from type int" )
return ans return ans
@ -705,9 +705,9 @@ def is_perfect_number(number):
""" """
# precondition # precondition
assert isinstance(number, int) and ( assert isinstance(number, int) and (number > 1), (
number > 1 "'number' must been an int and >= 1"
), "'number' must been an int and >= 1" )
divisors = get_divisors(number) divisors = get_divisors(number)

View File

@ -160,9 +160,9 @@ class _DataSet:
self._num_examples = 10000 self._num_examples = 10000
self.one_hot = one_hot self.one_hot = one_hot
else: else:
assert ( assert images.shape[0] == labels.shape[0], (
images.shape[0] == labels.shape[0] f"images.shape: {images.shape} labels.shape: {labels.shape}"
), f"images.shape: {images.shape} labels.shape: {labels.shape}" )
self._num_examples = images.shape[0] self._num_examples = images.shape[0]
# Convert shape from [num examples, rows, columns, depth] # Convert shape from [num examples, rows, columns, depth]

View File

@ -94,6 +94,6 @@ def test_project_euler(solution_path: pathlib.Path) -> None:
solution_module = convert_path_to_module(solution_path) solution_module = convert_path_to_module(solution_path)
answer = str(solution_module.solution()) answer = str(solution_module.solution())
answer = hashlib.sha256(answer.encode()).hexdigest() answer = hashlib.sha256(answer.encode()).hexdigest()
assert ( assert answer == expected, (
answer == expected f"Expected solution to {problem_number} to have hash {expected}, got {answer}"
), f"Expected solution to {problem_number} to have hash {expected}, got {answer}" )

View File

@ -33,7 +33,9 @@ def jaro_winkler(str1: str, str2: str) -> float:
right = int(min(i + limit + 1, len(_str2))) right = int(min(i + limit + 1, len(_str2)))
if char in _str2[left:right]: if char in _str2[left:right]:
matched.append(char) matched.append(char)
_str2 = f"{_str2[0:_str2.index(char)]} {_str2[_str2.index(char) + 1:]}" _str2 = (
f"{_str2[0 : _str2.index(char)]} {_str2[_str2.index(char) + 1 :]}"
)
return "".join(matched) return "".join(matched)