Skip to content

fix(hook): prevent triggering ConstructableEvent classes directly - #38

Merged
JohnRichard4096 merged 2 commits into
mainfrom
fix-hook
Aug 7, 2026
Merged

fix(hook): prevent triggering ConstructableEvent classes directly#38
JohnRichard4096 merged 2 commits into
mainfrom
fix-hook

Conversation

@JohnRichard4096

@JohnRichard4096 JohnRichard4096 commented Aug 7, 2026

Copy link
Copy Markdown
Member
  • Make ConstructableEvent generic with stringSub_T for proper typing
  • Raise TypeError when a ConstructableEvent class is used directly as a trigger
  • Downgrade "No registered Matcher" log level from warning to info

Summary by Sourcery

Prevent direct triggering of constructable event classes and improve typing for constructable events.

Bug Fixes:

  • Raise a TypeError when a ConstructableEvent class is passed directly to trigger_event instead of an event instance.

Enhancements:

  • Make ConstructableEvent generic over the event type for stronger typing.
  • Lower the log level to info when no matcher is registered for an event type.

Build:

  • Bump project version to 0.6.1 to reflect the changes.

- Make ConstructableEvent generic with stringSub_T for proper typing
- Raise TypeError when a ConstructableEvent class is used directly as a trigger
- Downgrade "No registered Matcher" log level from warning to info
@sourcery-ai

sourcery-ai Bot commented Aug 7, 2026

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

Reviewer's Guide

Prevents ConstructableEvent subclasses from being directly triggered, improves typing for ConstructableEvent, and downgrades the "No registered Matcher" log from warning to info while bumping the project patch version.

Sequence diagram for trigger_event handling of ConstructableEvent classes

sequenceDiagram
    actor Caller
    participant trigger_event
    participant ConstructableEventSubclass
    participant Logger

    Caller->>trigger_event: trigger_event(event, **kwargs)
    alt [event is type and issubclass ConstructableEvent]
        trigger_event-->>Caller: TypeError("Cannot trigger ConstructableEvent class directly")
    else [event is instance]
        trigger_event->>ConstructableEventSubclass: get_event_type()
        ConstructableEventSubclass-->>trigger_event: event_type
        alt [no matcher registered]
            trigger_event->>Logger: info("No registered Matcher for event, skipping processing")
        end
    end
Loading

File-Level Changes

Change Details Files
Add guard against using ConstructableEvent classes directly in trigger_event and adjust logging level when no matcher is found.
  • Import ConstructableEvent alongside BaseEvent into the matcher module
  • Detect when trigger_event receives a ConstructableEvent class instead of an instance and raise a TypeError with guidance to use TRIGGER_EVENT node
  • Change the log level for "No registered Matcher" situations from warning to info
src/amrita_sense/hook/matcher.py
Make ConstructableEvent generic for better type safety and document its role.
  • Update ConstructableEvent to inherit from BaseEvent parametrized with stringSub_T and Generic[stringSub_T]
  • Add a docstring explaining that ConstructableEvent is for TRIGGER_EVENT to construct events from an args-pool
src/amrita_sense/hook/event.py
Bump package patch version to reflect the behavioral and typing changes.
  • Increment project version from 0.6.0 to 0.6.1
pyproject.toml

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/amrita_sense/hook/matcher.py" line_range="532-537" />
<code_context>
+        if isinstance(event, type) and issubclass(
+            event, ConstructableEvent
+        ):  # In the future, we will support constructable event class directly.
+            raise TypeError(
+                "Cannot trigger ConstructableEvent class directly, please use constructable event in TRIGGER_EVENT node."
+            )
         session_kwargs = kwargs
</code_context>
<issue_to_address>
**suggestion:** Include the offending event class in the `TypeError` message for easier debugging

Consider including the rejected class in the message, e.g.:

```python
raise TypeError(
    f"Cannot trigger ConstructableEvent class {event!r} directly; "
    "please use a constructable event in TRIGGER_EVENT node."
)
```
so logs and stack traces clearly show which subclass caused the error when multiple `ConstructableEvent` types exist.

```suggestion
        if isinstance(event, type) and issubclass(
            event, ConstructableEvent
        ):  # In the future, we will support constructable event class directly.
            raise TypeError(
                f"Cannot trigger ConstructableEvent class {event!r} directly; "
                "please use a constructable event in TRIGGER_EVENT node."
            )
```
</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 src/amrita_sense/hook/matcher.py
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@JohnRichard4096
JohnRichard4096 merged commit 8bcab14 into main Aug 7, 2026
17 checks passed
@JohnRichard4096
JohnRichard4096 deleted the fix-hook branch August 7, 2026 07:48
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