From de06c260b42b6f733c26fbcbdffb11c27be1fd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BHUMIKA=20KADU=E2=9C=A8?= Date: Mon, 7 Sep 2026 18:04:40 +0000 Subject: [PATCH 1/7] Fix ty invalid assignment diagnostics --- cellular_automata/conways_game_of_life.py | 1 + cellular_automata/one_dimensional.py | 1 + .../binary_tree/non_recursive_segment_tree.py | 5 ++-- data_structures/heap/binomial_heap.py | 2 ++ .../linked_list/doubly_linked_list.py | 29 +++++++++++++++---- .../linked_list/singly_linked_list.py | 11 +++++-- fractals/mandelbrot.py | 1 + machine_learning/automatic_differentiation.py | 2 +- networking_flow/minimum_cut.py | 2 +- neural_network/input_data.py | 1 + pyproject.toml | 1 - scheduling/cpuschedulingalgorithms.py | 5 +++- 12 files changed, 47 insertions(+), 14 deletions(-) diff --git a/cellular_automata/conways_game_of_life.py b/cellular_automata/conways_game_of_life.py index 485f0d47bd8b..4009d0e1b7ae 100644 --- a/cellular_automata/conways_game_of_life.py +++ b/cellular_automata/conways_game_of_life.py @@ -78,6 +78,7 @@ def generate_images(cells: list[list[int]], frames: int) -> list[Image.Image]: # Create output image img = Image.new("RGB", (len(cells[0]), len(cells))) pixels = img.load() + assert pixels is not None # Save cells to image for x in range(len(cells)): diff --git a/cellular_automata/one_dimensional.py b/cellular_automata/one_dimensional.py index da77e444502f..04d55c2473e8 100644 --- a/cellular_automata/one_dimensional.py +++ b/cellular_automata/one_dimensional.py @@ -55,6 +55,7 @@ def generate_image(cells: list[list[int]]) -> Image.Image: # Create the output image img = Image.new("RGB", (len(cells[0]), len(cells))) pixels = img.load() + assert pixels is not None # Generates image for w in range(img.width): for h in range(img.height): diff --git a/data_structures/binary_tree/non_recursive_segment_tree.py b/data_structures/binary_tree/non_recursive_segment_tree.py index 7d1c965fab50..0108dcade281 100644 --- a/data_structures/binary_tree/non_recursive_segment_tree.py +++ b/data_structures/binary_tree/non_recursive_segment_tree.py @@ -39,7 +39,7 @@ from __future__ import annotations from collections.abc import Callable -from typing import Any, TypeVar +from typing import Any, TypeVar, cast T = TypeVar("T") @@ -57,10 +57,9 @@ def __init__(self, arr: list[T], fnc: Callable[[T, T], T]) -> None: ... lambda a, b: (a[0] + b[0], a[1] + b[1])).query(0, 2) (6, 9) """ - any_type: Any | T = None self.N: int = len(arr) - self.st: list[T] = [any_type for _ in range(self.N)] + arr + self.st: list[T] = [cast(T,None) for _ in range(self.N)] + arr self.fn = fnc self.build() diff --git a/data_structures/heap/binomial_heap.py b/data_structures/heap/binomial_heap.py index 9cfdf0c12fe0..c97ec1c32149 100644 --- a/data_structures/heap/binomial_heap.py +++ b/data_structures/heap/binomial_heap.py @@ -222,6 +222,7 @@ def insert(self, val): if val < self.min_node.val: self.min_node = new_node # Put new_node as a bottom_root in heap + assert self.bottom_root is not None self.bottom_root.left = new_node new_node.parent = self.bottom_root self.bottom_root = new_node @@ -283,6 +284,7 @@ def delete_min(self): # Update bottom root self.bottom_root = self.bottom_root.parent + assert self.bottom_root is not None self.bottom_root.left = None # Update min_node diff --git a/data_structures/linked_list/doubly_linked_list.py b/data_structures/linked_list/doubly_linked_list.py index bd3445f9f6c5..695f5f2111cc 100644 --- a/data_structures/linked_list/doubly_linked_list.py +++ b/data_structures/linked_list/doubly_linked_list.py @@ -1,13 +1,16 @@ """ https://en.wikipedia.org/wiki/Doubly_linked_list """ +from __future__ import annotations + +from typing import Any class Node: - def __init__(self, data): + def __init__(self, data: Any): self.data = data - self.previous = None - self.next = None + self.previous: Node | None = None + self.next: Node | None = None def __str__(self): return f"{self.data}" @@ -15,8 +18,8 @@ def __str__(self): class DoublyLinkedList: def __init__(self): - self.head = None - self.tail = None + self.head: Node | None = None + self.tail: Node | None = None def __iter__(self): """ @@ -93,13 +96,18 @@ def insert_at_nth(self, index: int, data): new_node.next = self.head self.head = new_node elif index == length: + assert self.tail is not None self.tail.next = new_node + assert self.tail is not None new_node.previous = self.tail self.tail = new_node else: temp = self.head + assert temp is not None for _ in range(index): temp = temp.next + assert temp is not None + assert temp.previous is not None temp.previous.next = new_node new_node.previous = temp.previous new_node.next = temp @@ -141,23 +149,32 @@ def delete_at_nth(self, index: int): if length == 1: self.head = self.tail = None elif index == 0: + assert self.head is not None self.head = self.head.next + assert self.head is not None self.head.previous = None elif index == length - 1: + assert self.tail is not None delete_node = self.tail self.tail = self.tail.previous + assert self.tail is not None self.tail.next = None else: temp = self.head + assert temp is not None for _ in range(index): temp = temp.next + assert temp is not None delete_node = temp + assert temp.next is not None + assert temp.previous is not None temp.next.previous = temp.previous temp.previous.next = temp.next return delete_node.data def delete(self, data) -> str: current = self.head + assert current is not None while current.data != data: # Find the position to delete if current.next: @@ -172,6 +189,8 @@ def delete(self, data) -> str: self.delete_tail() else: # Before: 1 <--> 2(current) <--> 3 + assert current.previous is not None + assert current.next is not None current.previous.next = current.next # 1 --> 3 current.next.previous = current.previous # 1 <--> 3 return data diff --git a/data_structures/linked_list/singly_linked_list.py b/data_structures/linked_list/singly_linked_list.py index 2c6713a47ad9..3ec91242d62c 100644 --- a/data_structures/linked_list/singly_linked_list.py +++ b/data_structures/linked_list/singly_linked_list.py @@ -45,7 +45,7 @@ def __init__(self): >>> linked_list.head is None True """ - self.head = None + self.head: Node | None = None def __iter__(self) -> Iterator[Any]: """ @@ -153,8 +153,10 @@ def __setitem__(self, index: int, data: Any) -> None: if not 0 <= index < len(self): raise ValueError("list index out of range.") current = self.head + assert current is not None for _ in range(index): current = current.next_node + assert current is not None current.data = data def insert_tail(self, data: Any) -> None: @@ -215,8 +217,10 @@ def insert_nth(self, index: int, data: Any) -> None: self.head = new_node else: temp = self.head + assert temp is not None for _ in range(index - 1): temp = temp.next_node + assert temp is not None new_node.next_node = temp.next_node temp.next_node = new_node @@ -316,10 +320,13 @@ def delete_nth(self, index: int = 0) -> Any: self.head = self.head.next_node else: temp = self.head + assert temp is not None for _ in range(index - 1): temp = temp.next_node + assert temp is not None delete_node = temp.next_node - temp.next_node = temp.next_node.next_node + assert delete_node is not None + temp.next_node = delete_node.next_node return delete_node.data def is_empty(self) -> bool: diff --git a/fractals/mandelbrot.py b/fractals/mandelbrot.py index 359d965a882d..6b849c1b00a6 100644 --- a/fractals/mandelbrot.py +++ b/fractals/mandelbrot.py @@ -109,6 +109,7 @@ def get_image( """ img = Image.new("RGB", (image_width, image_height)) pixels = img.load() + assert pixels is not None # loop through the image-coordinates for image_x in range(image_width): diff --git a/machine_learning/automatic_differentiation.py b/machine_learning/automatic_differentiation.py index 93e77e761ef9..96a0f4b4ff77 100644 --- a/machine_learning/automatic_differentiation.py +++ b/machine_learning/automatic_differentiation.py @@ -258,7 +258,7 @@ def gradient(self, target: Variable, source: Variable) -> np.ndarray | None: """ # partial derivatives with respect to target - partial_deriv = defaultdict(lambda: 0) + partial_deriv: defaultdict[Variable, np.ndarray] = defaultdict(lambda: np.array(0)) partial_deriv[target] = np.ones_like(target.to_ndarray()) # iterating through each operations in the computation graph diff --git a/networking_flow/minimum_cut.py b/networking_flow/minimum_cut.py index c1f4a83b6aee..fbe170626faf 100644 --- a/networking_flow/minimum_cut.py +++ b/networking_flow/minimum_cut.py @@ -71,7 +71,7 @@ def mincut(graph: list[list[int]], source: int, sink: int) -> list[tuple[int, in parent = [-1] * (len(residual)) res = [] while bfs(residual, source, sink, parent): - path_flow = float("inf") + path_flow = max(max(row) for row in residual) s = sink while s != source: diff --git a/neural_network/input_data.py b/neural_network/input_data.py index 3a8628f939f8..7f0b7538df54 100644 --- a/neural_network/input_data.py +++ b/neural_network/input_data.py @@ -21,6 +21,7 @@ import os import typing import urllib +import urllib.request import numpy as np from tensorflow.python.framework import dtypes, random_seed diff --git a/pyproject.toml b/pyproject.toml index ab98e15b2a41..b07844cada7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,7 +191,6 @@ environment.python-version = "3.14" rules.call-non-callable = "ignore" rules.deprecated = "ignore" rules.invalid-argument-type = "ignore" -rules.invalid-assignment = "ignore" rules.invalid-parameter-default = "ignore" rules.invalid-return-type = "ignore" rules.invalid-type-arguments = "ignore" diff --git a/scheduling/cpuschedulingalgorithms.py b/scheduling/cpuschedulingalgorithms.py index 7a39d57a213f..aba85b482230 100644 --- a/scheduling/cpuschedulingalgorithms.py +++ b/scheduling/cpuschedulingalgorithms.py @@ -334,7 +334,10 @@ def add_process(self) -> None: def delete_process(self) -> None: """Deletes a selected process.""" if sel := self.tree.selection(): - pid = self.tree.item(sel[0])["values"][0] + values = self.tree.item(sel[0])["values"] + if not values: + return + pid = values[0] self.processes = [p for p in self.processes if p["pid"] != pid] self.tree.delete(sel[0]) From 54eb5580d05815ca8c273416e75c75dc70bca47d Mon Sep 17 00:00:00 2001 From: kadubhumika Date: Mon, 7 Sep 2026 18:05:22 +0000 Subject: [PATCH 2/7] updating DIRECTORY.md --- DIRECTORY.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 55af355f7fc0..2b344f964ad6 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -669,7 +669,9 @@ * Forecasting * [Run](machine_learning/forecasting/run.py) * [Frequent Pattern Growth](machine_learning/frequent_pattern_growth.py) + * [Gaussian Naive Bayes](machine_learning/gaussian_naive_bayes.py) * [Gradient Boosting Classifier](machine_learning/gradient_boosting_classifier.py) + * [Gradient Boosting Regressor](machine_learning/gradient_boosting_regressor.py) * [Gradient Descent](machine_learning/gradient_descent.py) * [K Means Clust](machine_learning/k_means_clust.py) * [K Nearest Neighbours](machine_learning/k_nearest_neighbours.py) @@ -685,6 +687,8 @@ * [Multilayer Perceptron Classifier](machine_learning/multilayer_perceptron_classifier.py) * [Polynomial Regression](machine_learning/polynomial_regression.py) * [Principle Component Analysis](machine_learning/principle_component_analysis.py) + * [Random Forest Classifier](machine_learning/random_forest_classifier.py) + * [Random Forest Regressor](machine_learning/random_forest_regressor.py) * [Scoring Functions](machine_learning/scoring_functions.py) * [Self Organizing Map](machine_learning/self_organizing_map.py) * [Sequential Minimum Optimization](machine_learning/sequential_minimum_optimization.py) @@ -923,6 +927,7 @@ * [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py) * [Convolution Neural Network](neural_network/convolution_neural_network.py) * [Input Data](neural_network/input_data.py) + * [Perceptron](neural_network/perceptron.py) * [Simple Neural Network](neural_network/simple_neural_network.py) * [Two Hidden Layers Neural Network](neural_network/two_hidden_layers_neural_network.py) @@ -975,6 +980,7 @@ * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) * [Malus Law](physics/malus_law.py) * [Mass Energy Equivalence](physics/mass_energy_equivalence.py) + * [Maxwells Equations](physics/maxwells_equations.py) * [Mirror Formulae](physics/mirror_formulae.py) * [N Body Simulation](physics/n_body_simulation.py) * [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py) From 79764c1a5e0bbefbe93a1d60635cf2a83a2a45d8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Sep 2026 18:23:26 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/binary_tree/non_recursive_segment_tree.py | 2 +- data_structures/linked_list/doubly_linked_list.py | 1 + machine_learning/automatic_differentiation.py | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/non_recursive_segment_tree.py b/data_structures/binary_tree/non_recursive_segment_tree.py index 0108dcade281..bea58bf7eee8 100644 --- a/data_structures/binary_tree/non_recursive_segment_tree.py +++ b/data_structures/binary_tree/non_recursive_segment_tree.py @@ -59,7 +59,7 @@ def __init__(self, arr: list[T], fnc: Callable[[T, T], T]) -> None: """ self.N: int = len(arr) - self.st: list[T] = [cast(T,None) for _ in range(self.N)] + arr + self.st: list[T] = [cast(T, None) for _ in range(self.N)] + arr self.fn = fnc self.build() diff --git a/data_structures/linked_list/doubly_linked_list.py b/data_structures/linked_list/doubly_linked_list.py index 695f5f2111cc..1eee15edf714 100644 --- a/data_structures/linked_list/doubly_linked_list.py +++ b/data_structures/linked_list/doubly_linked_list.py @@ -1,6 +1,7 @@ """ https://en.wikipedia.org/wiki/Doubly_linked_list """ + from __future__ import annotations from typing import Any diff --git a/machine_learning/automatic_differentiation.py b/machine_learning/automatic_differentiation.py index 96a0f4b4ff77..4952328ab9c2 100644 --- a/machine_learning/automatic_differentiation.py +++ b/machine_learning/automatic_differentiation.py @@ -258,7 +258,9 @@ def gradient(self, target: Variable, source: Variable) -> np.ndarray | None: """ # partial derivatives with respect to target - partial_deriv: defaultdict[Variable, np.ndarray] = defaultdict(lambda: np.array(0)) + partial_deriv: defaultdict[Variable, np.ndarray] = defaultdict( + lambda: np.array(0) + ) partial_deriv[target] = np.ones_like(target.to_ndarray()) # iterating through each operations in the computation graph From 8b2ef93f2c66dda23e6b38deaa96659941c9c709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BHUMIKA=20KADU=E2=9C=A8?= Date: Mon, 7 Sep 2026 18:27:59 +0000 Subject: [PATCH 4/7] Fix unused typing import --- data_structures/binary_tree/non_recursive_segment_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/binary_tree/non_recursive_segment_tree.py b/data_structures/binary_tree/non_recursive_segment_tree.py index bea58bf7eee8..d2f36547ca69 100644 --- a/data_structures/binary_tree/non_recursive_segment_tree.py +++ b/data_structures/binary_tree/non_recursive_segment_tree.py @@ -39,7 +39,7 @@ from __future__ import annotations from collections.abc import Callable -from typing import Any, TypeVar, cast +from typing import TypeVar, cast T = TypeVar("T") From 2d7f5d2e00661257e25b7d19ba8178691e9e2552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BHUMIKA=20KADU=E2=9C=A8?= Date: Mon, 7 Sep 2026 18:53:49 +0000 Subject: [PATCH 5/7] Fix gradient accumulation type handling --- machine_learning/automatic_differentiation.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/machine_learning/automatic_differentiation.py b/machine_learning/automatic_differentiation.py index 4952328ab9c2..1c9c3cf7fb4a 100644 --- a/machine_learning/automatic_differentiation.py +++ b/machine_learning/automatic_differentiation.py @@ -258,9 +258,7 @@ def gradient(self, target: Variable, source: Variable) -> np.ndarray | None: """ # partial derivatives with respect to target - partial_deriv: defaultdict[Variable, np.ndarray] = defaultdict( - lambda: np.array(0) - ) + partial_deriv: dict[Variable, np.ndarray] = {} partial_deriv[target] = np.ones_like(target.to_ndarray()) # iterating through each operations in the computation graph @@ -272,7 +270,7 @@ def gradient(self, target: Variable, source: Variable) -> np.ndarray | None: # of variables with respect to the target dparam_doutput = self.derivative(param, operation) dparam_dtarget = dparam_doutput * partial_deriv[operation.output] - partial_deriv[param] += dparam_dtarget + partial_deriv[param] = partial_deriv.get(param, np.zeros_like(dparam_dtarget)) + dparam_dtarget if param.result_of and param.result_of != OpType.NOOP: operation_queue.append(param.result_of) From df2fe0dbc511621781b1533f2ba560fdf0543b9c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Sep 2026 18:54:23 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/automatic_differentiation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/machine_learning/automatic_differentiation.py b/machine_learning/automatic_differentiation.py index 1c9c3cf7fb4a..11f03d89712c 100644 --- a/machine_learning/automatic_differentiation.py +++ b/machine_learning/automatic_differentiation.py @@ -270,7 +270,10 @@ def gradient(self, target: Variable, source: Variable) -> np.ndarray | None: # of variables with respect to the target dparam_doutput = self.derivative(param, operation) dparam_dtarget = dparam_doutput * partial_deriv[operation.output] - partial_deriv[param] = partial_deriv.get(param, np.zeros_like(dparam_dtarget)) + dparam_dtarget + partial_deriv[param] = ( + partial_deriv.get(param, np.zeros_like(dparam_dtarget)) + + dparam_dtarget + ) if param.result_of and param.result_of != OpType.NOOP: operation_queue.append(param.result_of) From 7a8a49a9d19eb9409d731ee06e4fcaab890184b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BHUMIKA=20KADU=E2=9C=A8?= Date: Mon, 7 Sep 2026 19:03:23 +0000 Subject: [PATCH 7/7] Fix automatic differentiation gradient dtype handling --- machine_learning/automatic_differentiation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/machine_learning/automatic_differentiation.py b/machine_learning/automatic_differentiation.py index 11f03d89712c..ced44b9a7c27 100644 --- a/machine_learning/automatic_differentiation.py +++ b/machine_learning/automatic_differentiation.py @@ -9,7 +9,6 @@ from __future__ import annotations -from collections import defaultdict from enum import Enum from types import TracebackType from typing import Any, Self