fix(hook): prevent triggering ConstructableEvent classes directly - #38
Merged
Conversation
- 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
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuidePrevents 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 classessequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Prevent direct triggering of constructable event classes and improve typing for constructable events.
Bug Fixes:
Enhancements:
Build: