Skip to content

fix: SupportSTDP.stdp_update keyword typo and DSRunner deprecation warning#864

Merged
chaoming0625 merged 1 commit into
masterfrom
fix-stdp-warn
Jul 9, 2026
Merged

fix: SupportSTDP.stdp_update keyword typo and DSRunner deprecation warning#864
chaoming0625 merged 1 commit into
masterfrom
fix-stdp-warn

Conversation

@chaoming0625

@chaoming0625 chaoming0625 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Fixes the two latent runtime bugs flagged during the package-wide mypy pass (#863).

1. brainpy/mixin.pyonn_post keyword typo

The base SupportSTDP.stdp_update placeholder declared the keyword onn_post, while every concrete override (brainpy/dnn/linear.py) and every caller (brainpy/dyn/projections/plasticity.py, tests) uses on_post. The placeholder body only raise NotImplementedError, so this was a contract/signature defect rather than a wrong-result bug, but it was the source of the STDP [override] friction. Signature aligned to on_post.

The five overrides keep their targeted # type: ignore[override] (the base remains a permissive *args/**kwargs placeholder vs. their explicit params, so the LSP mismatch stands), but their comments no longer reference the now-fixed typo.

2. brainpy/runners.py:455raise warnings.warn(...)

DSRunner.predict did raise warnings.warn(...) for the deprecated inputs_are_batching argument. warnings.warn returns None, so raise None produced TypeError: exceptions must derive from BaseException instead of a warning. Now emits the UserWarning and continues, as intended.

Validation

  • python -m mypy brainpy/Success: no issues found in 432 source files.
  • New runtime check: predict(..., inputs_are_batching=True) now warns and continues (previously raised TypeError).
  • Base SupportSTDP.stdp_update now accepts on_post= and still raises NotImplementedError.
  • STDP suites (boost_linear_test.py, mixin_coverage_test.py, test_dense_stdp_update_promotes_weight): 91 passed.

Summary by Sourcery

Align STDP mixin and linear layer signatures and fix DSRunner deprecation handling so it emits a warning instead of raising an error.

Bug Fixes:

  • Correct the SupportSTDP.stdp_update keyword name from onn_post to on_post to match concrete implementations and callers.
  • Fix DSRunner.predict to use warnings.warn for the deprecated inputs_are_batching argument instead of incorrectly raising its return value.

…rning

- 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.
@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Aligns the SupportSTDP.stdp_update interface with its concrete implementations by fixing a keyword typo, and corrects DSRunner.predict’s deprecation handling to emit a warning instead of raising a TypeError.

Sequence diagram for DSRunner.predict deprecation warning flow

sequenceDiagram
actor User
participant DSRunner
participant warnings
User->>DSRunner: predict(inputs, inputs_are_batching)
alt inputs_are_batching is not None
  DSRunner->>warnings: warn(message, UserWarning)
end
DSRunner-->>User: prediction_result
Loading

File-Level Changes

Change Details Files
Align SupportSTDP.stdp_update signature keyword with all concrete overrides and callers.
  • Rename the placeholder parameter from onn_post to on_post in SupportSTDP.stdp_update while keeping *args/**kwargs and raising NotImplementedError.
  • Leave override methods in linear STDP modules unchanged in behavior but retain their explicit signatures and targeted type: ignore[override] annotations.
  • Update inline comments on stdp_update overrides to remove references to the old onn_post typo while still explaining the override vs. permissive base signature mismatch.
brainpy/mixin.py
brainpy/dnn/linear.py
Fix DSRunner.predict deprecation handling so inputs_are_batching triggers a warning and does not raise.
  • Replace raise warnings.warn(...) with a direct warnings.warn(...) call to avoid raising None.
  • Keep the deprecation message content and UserWarning type the same, aside from trimming trailing whitespace in the message string.
brainpy/runners.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chaoming0625 chaoming0625 merged commit 0c5a070 into master Jul 9, 2026
5 of 13 checks passed
@chaoming0625 chaoming0625 deleted the fix-stdp-warn branch July 9, 2026 01:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Consider aligning the SupportSTDP.stdp_update signature with the concrete implementations (dropping *args/**kwargs and using explicit parameters) so the override relationship is LSP-compliant and the # type: ignore[override] hints can eventually be removed.
  • In DSRunner.predict, you may want to set an explicit stacklevel on warnings.warn so that the deprecation warning points at the caller rather than the internal runner implementation.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider aligning the `SupportSTDP.stdp_update` signature with the concrete implementations (dropping `*args/**kwargs` and using explicit parameters) so the override relationship is LSP-compliant and the `# type: ignore[override]` hints can eventually be removed.
- In `DSRunner.predict`, you may want to set an explicit `stacklevel` on `warnings.warn` so that the deprecation warning points at the caller rather than the internal runner implementation.

## Individual Comments

### Comment 1
<location path="brainpy/runners.py" line_range="455-460" />
<code_context>

         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
</code_context>
<issue_to_address>
**suggestion:** Refine the warning to give a clearer location and potentially a more specific warning type.

With the misuse of `raise warnings.warn(...)` corrected, consider setting an appropriate `stacklevel` (e.g., `stacklevel=2`) so the warning points to the caller instead of the runner internals. Since this concerns a deprecated argument, using `DeprecationWarning` or a dedicated warning subclass instead of `UserWarning` would better express the deprecation intent.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread brainpy/runners.py
Comment on lines +455 to 460
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Refine the warning to give a clearer location and potentially a more specific warning type.

With the misuse of raise warnings.warn(...) corrected, consider setting an appropriate stacklevel (e.g., stacklevel=2) so the warning points to the caller instead of the runner internals. Since this concerns a deprecated argument, using DeprecationWarning or a dedicated warning subclass instead of UserWarning would better express the deprecation intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant