-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Typing of Event Handlers #3523
Conversation
Reviewer's Guide by SourceryThis pull request enhances the typing of event handlers across multiple files by introducing the OptionalEventCallable type. It updates the type annotations for event handler parameters to use this new type and simplifies event handler lambda functions by removing json.loads and directly passing the event. File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ndonkoHenri - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 7 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
self.__on_tap_down = EventHandler(lambda e: TapEvent(**json.loads(e.data))) | ||
self.__on_tap_down = EventHandler(lambda e: TapEvent(e)) | ||
self._add_event_handler("tap_down", self.__on_tap_down.get_handler()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential data loss in event handler
The change from json.loads(e.data)
to e
directly in the event handler might lead to data loss if e
is not a JSON string. Ensure that e
is always a JSON string or modify the TapEvent
class to handle raw event data appropriately.
@@ -53,9 +59,12 @@ def __init__(self, path, files) -> None: | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential issue with file list handling
Ensure that d["files"]
is always a list. If there's a possibility of it being None
or another type, additional checks might be necessary to avoid runtime errors.
+1 |
* Enhance typing of event handlers | reformat *Event classes * rename OptionalEventCallback to OptionalEventCallable --------- Co-authored-by: Feodor Fitsner <feodor@appveyor.com>
Summary by Sourcery
This pull request enhances the typing of event handlers across multiple modules by introducing the OptionalEventCallable type. It simplifies event handler initialization and improves type safety and clarity in the codebase.