From 3b3253b2d87e4673fd87c7ec825644a3d02d1fd9 Mon Sep 17 00:00:00 2001 From: kvadrik <41710943+kvadrik@users.noreply.github.com> Date: Wed, 18 Feb 2026 23:19:08 +0200 Subject: [PATCH 1/6] Update volume.py --- maths/volume.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/maths/volume.py b/maths/volume.py index 1715c9c300d5..a31c9d53e381 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -509,6 +509,30 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float: raise ValueError("vol_torus() only accepts non-negative values") return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2) +def vol_octahedron(oct_side: float) -> float: + """ + | Calculate the Volume of an Octahedron. + | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_octahedron + + >>> from math import isclose + >>> isclose(vol_octahedron(2.5), 7.36569563735987) + True + >>> isclose(vol_octahedron(10), 471.40452079103168) + True + >>> isclose(vol_octahedron(5), 58.92556509887896) + True + >>> isclose(vol_octahedron(3.5), 20.21146882891548) + True + >>> vol_octahedron(0) + 0.0 + >>> vol_octahedron(-1) + Traceback (most recent call last): + ... + ValueError: vol_octahedron() only accepts non-negative values + """ + if oct_side < 0: + raise ValueError("vol_octahedron() only accepts non-negative values") + return oct_side**3 * 2**0.5 / 3 def vol_icosahedron(tri_side: float) -> float: """ @@ -560,6 +584,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 + print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09 From 4134ea75bc005c9b99c8c7ca5c162fa804d8c34f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:21:47 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/volume.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maths/volume.py b/maths/volume.py index a31c9d53e381..f48d388b423e 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -509,6 +509,7 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float: raise ValueError("vol_torus() only accepts non-negative values") return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2) + def vol_octahedron(oct_side: float) -> float: """ | Calculate the Volume of an Octahedron. @@ -534,6 +535,7 @@ def vol_octahedron(oct_side: float) -> float: raise ValueError("vol_octahedron() only accepts non-negative values") return oct_side**3 * 2**0.5 / 3 + def vol_icosahedron(tri_side: float) -> float: """ | Calculate the Volume of an Icosahedron. @@ -584,7 +586,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 - print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 + print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09 From 619a4a70968987de7595d3d41dbb07475d4de4be Mon Sep 17 00:00:00 2001 From: kvadrik <41710943+kvadrik@users.noreply.github.com> Date: Fri, 27 Feb 2026 11:54:41 +0200 Subject: [PATCH 3/6] refactor: remove unnecessary empty iterable in deque (RUF037) Clean up trailing whitespace and empty list in deque initialization to satisfy Ruff linting rules. --- data_structures/hashing/hash_table_with_linked_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/hashing/hash_table_with_linked_list.py b/data_structures/hashing/hash_table_with_linked_list.py index f404c5251246..c8dffa30b8e8 100644 --- a/data_structures/hashing/hash_table_with_linked_list.py +++ b/data_structures/hashing/hash_table_with_linked_list.py @@ -8,7 +8,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _set_value(self, key, data): - self.values[key] = deque([]) if self.values[key] is None else self.values[key] + self.values[key] = deque() if self.values[key] is None else self.values[key] self.values[key].appendleft(data) self._keys[key] = self.values[key] From 8dcb65b7b01ec258c34364ff9a201ef4d5801eff Mon Sep 17 00:00:00 2001 From: kvadrik <41710943+kvadrik@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:40:17 +0200 Subject: [PATCH 4/6] style: update valid_input to use Python 3.12 type parameters Applied PEP 695 syntax to the valid_input function by moving the 'num' generic into brackets. This resolves the UP047 error in the machine_learning directory. --- machine_learning/linear_discriminant_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/linear_discriminant_analysis.py b/machine_learning/linear_discriminant_analysis.py index 8528ccbbae51..af5248c4dbc4 100644 --- a/machine_learning/linear_discriminant_analysis.py +++ b/machine_learning/linear_discriminant_analysis.py @@ -252,7 +252,7 @@ def accuracy(actual_y: list, predicted_y: list) -> float: num = TypeVar("num") -def valid_input( +def valid_input[num]( input_type: Callable[[object], num], # Usually float or int input_msg: str, err_msg: str, From 634e0afe59f8bfec9758ae0a6d43c6082e33cdbe Mon Sep 17 00:00:00 2001 From: kvadrik <41710943+kvadrik@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:44:40 +0200 Subject: [PATCH 5/6] style: update generic functions to Python 3.12 syntax (UP047) Refactor jump_search to use PEP 695 type parameters [T] as required by the latest Ruff configuration. --- searches/jump_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searches/jump_search.py b/searches/jump_search.py index e72d85e8a868..cf19af2432c2 100644 --- a/searches/jump_search.py +++ b/searches/jump_search.py @@ -20,7 +20,7 @@ def __lt__(self, other: Any, /) -> bool: ... T = TypeVar("T", bound=Comparable) -def jump_search(arr: Sequence[T], item: T) -> int: +def jump_search[T](arr: Sequence[T], item: T) -> int: """ Python implementation of the jump search algorithm. Return the index if the `item` is found, otherwise return -1. From 87aad764cdee190ba38940d0a6f67990add9ea3d Mon Sep 17 00:00:00 2001 From: kvadrik <41710943+kvadrik@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:52:29 +0200 Subject: [PATCH 6/6] fix(types): add Comparable bound to jump_search type parameter Updated the PEP 695 type parameter syntax to include the 'Comparable' bound. This resolves the Mypy error regarding unsupported left operand types for the '<' operator, ensuring that the generic type T supports comparisons. --- searches/jump_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searches/jump_search.py b/searches/jump_search.py index cf19af2432c2..b443d09283b0 100644 --- a/searches/jump_search.py +++ b/searches/jump_search.py @@ -20,7 +20,7 @@ def __lt__(self, other: Any, /) -> bool: ... T = TypeVar("T", bound=Comparable) -def jump_search[T](arr: Sequence[T], item: T) -> int: +def jump_search[T: Comparable](arr: Sequence[T], item: T) -> int: """ Python implementation of the jump search algorithm. Return the index if the `item` is found, otherwise return -1.