From 550f5b7c5881917034ee6cac1ffe5033f18b5702 Mon Sep 17 00:00:00 2001 From: chaoming Date: Thu, 9 Jul 2026 09:44:35 +0800 Subject: [PATCH] fix: SupportSTDP.stdp_update keyword typo and DSRunner deprecation warning - mixin.py: the base SupportSTDP.stdp_update placeholder declared the keyword `onn_post` (typo) while every concrete override and caller uses `on_post`. Align the placeholder signature. The five overrides in dnn/linear.py keep their targeted `# type: ignore[override]` (the base stays a permissive *args/**kwargs placeholder vs. their explicit params), but the comments no longer reference the now-fixed typo. - runners.py: DSRunner.predict raised `warnings.warn(...)` for the deprecated `inputs_are_batching` argument. `warnings.warn` returns None, so `raise` produced `TypeError: exceptions must derive from BaseException` instead of a warning. Emit the UserWarning and continue, as intended. Verified: `mypy brainpy/` stays clean (432 files); STDP suites (91 tests) and the DSRunner warn-path pass. --- brainpy/dnn/linear.py | 10 +++++----- brainpy/mixin.py | 2 +- brainpy/runners.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/brainpy/dnn/linear.py b/brainpy/dnn/linear.py index 9e111c7b..40af4ca0 100644 --- a/brainpy/dnn/linear.py +++ b/brainpy/dnn/linear.py @@ -226,7 +226,7 @@ def offline_fit(self, self.W.value = Wff self.b.value = bias[0] - def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder (with an `onn_post` typo); concrete overrides declare explicit params + def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder; concrete overrides declare explicit params self, on_pre: Optional[Dict] = None, on_post: Optional[Dict] = None, @@ -334,7 +334,7 @@ def update(self, pre_val): post_val = pre_val @ self.weight return post_val - def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder (with an `onn_post` typo); concrete overrides declare explicit params + def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder; concrete overrides declare explicit params self, on_pre: Optional[Dict] = None, on_post: Optional[Dict] = None, @@ -397,7 +397,7 @@ def __init__( def update(self, pre_val): return pre_val * self.weight - def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder (with an `onn_post` typo); concrete overrides declare explicit params + def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder; concrete overrides declare explicit params self, on_pre: Optional[Dict] = None, on_post: Optional[Dict] = None, @@ -484,7 +484,7 @@ def __init__( def update(self, x): return x @ self.mask_fun(self.weight * self.mask) - def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder (with an `onn_post` typo); concrete overrides declare explicit params + def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder; concrete overrides declare explicit params self, on_pre: Optional[Dict] = None, on_post: Optional[Dict] = None, @@ -535,7 +535,7 @@ def __init__( w = bm.TrainVar(w) self.weight = w - def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder (with an `onn_post` typo); concrete overrides declare explicit params + def stdp_update( # type: ignore[override] # base SupportSTDP.stdp_update is a permissive *args/**kwargs placeholder; concrete overrides declare explicit params self, on_pre: Optional[Dict] = None, on_post: Optional[Dict] = None, diff --git a/brainpy/mixin.py b/brainpy/mixin.py index fdfc3c64..8a3a4339 100644 --- a/brainpy/mixin.py +++ b/brainpy/mixin.py @@ -544,5 +544,5 @@ class SupportSTDP(MixIn): """Support synaptic plasticity by modifying the weights. """ - def stdp_update(self, *args, on_pre=None, onn_post=None, **kwargs): + def stdp_update(self, *args, on_pre=None, on_post=None, **kwargs): raise NotImplementedError diff --git a/brainpy/runners.py b/brainpy/runners.py index b82642cb..dbcbdd1a 100644 --- a/brainpy/runners.py +++ b/brainpy/runners.py @@ -452,9 +452,9 @@ def predict( """ if inputs_are_batching is not None: - raise warnings.warn( # type: ignore[misc] # latent bug: warnings.warn returns None; preserved to avoid behavior change + warnings.warn( f''' - `inputs_are_batching` is no longer supported. + `inputs_are_batching` is no longer supported. The target mode of {self.target.mode} has already indicated the input should be batching. ''', UserWarning