From 85aa78348d4ffa063e90f091e9174d2050ce9657 Mon Sep 17 00:00:00 2001 From: GeorgeLey Date: Thu, 12 Nov 2026 22:17:24 -0700 Subject: [PATCH] chore(ty): rename stale rule names and un-ignore not-callable ty 0.0.102 renamed four rules in the [tool.ty] ignore list, so every run emitted renamed-rule warnings. Use the current names (invalid-explicit-return, missing-attribute, import-not-found) and drop not-callable (formerly call-non-callable) from the list after fixing its only diagnostic: DenseLayer.activation could be None when called, so the sigmoid default now happens in __init__ and the parameters are typed. Part of #15187 Co-Authored-By: Claude Opus 5.5 --- neural_network/back_propagation_neural_network.py | 14 +++++++++----- pyproject.toml | 7 +++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/neural_network/back_propagation_neural_network.py b/neural_network/back_propagation_neural_network.py index 04fd7be84331..6c0dbeeec195 100644 --- a/neural_network/back_propagation_neural_network.py +++ b/neural_network/back_propagation_neural_network.py @@ -18,6 +18,8 @@ """ +from collections.abc import Callable + import numpy as np from matplotlib import pyplot as plt @@ -32,19 +34,23 @@ class DenseLayer: """ def __init__( - self, units, activation=None, learning_rate=None, is_input_layer=False + self, + units: int, + activation: Callable[[np.ndarray], np.ndarray] | None = None, + learning_rate: float | None = None, + is_input_layer: bool = False, ) -> None: """ common connected layer of bp network :param units: numbers of neural units - :param activation: activation function + :param activation: activation function (defaults to sigmoid) :param learning_rate: learning rate for paras :param is_input_layer: whether it is input layer or not """ self.units = units self.weight = None self.bias = None - self.activation = activation + self.activation = activation if activation is not None else sigmoid if learning_rate is None: learning_rate = 0.3 self.learn_rate = learning_rate @@ -54,8 +60,6 @@ def initializer(self, back_units) -> None: rng = np.random.default_rng() self.weight = np.asmatrix(rng.normal(0, 0.5, (self.units, back_units))) self.bias = np.asmatrix(rng.normal(0, 0.5, self.units)).T - if self.activation is None: - self.activation = sigmoid def cal_gradient(self): # activation function may be sigmoid or linear diff --git a/pyproject.toml b/pyproject.toml index 932f64f2e00a..629e3a67e960 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -316,15 +316,14 @@ skip = """\ # assumptions consistent with the CI job in .github/workflows/ty.yml, where the # free-threaded 3.15t test venv would otherwise leave several stubs unresolved. environment.python-version = "3.15" -rules.call-non-callable = "ignore" +rules.import-not-found = "ignore" rules.invalid-argument-type = "ignore" -rules.invalid-return-type = "ignore" +rules.invalid-explicit-return = "ignore" +rules.missing-attribute = "ignore" rules.no-matching-overload = "ignore" rules.not-iterable = "ignore" rules.not-subscriptable = "ignore" rules.parameter-already-assigned = "ignore" -rules.unresolved-attribute = "ignore" -rules.unresolved-import = "ignore" rules.unsupported-operator = "ignore" [tool.pytest]