-
Notifications
You must be signed in to change notification settings - Fork 472
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
Refactor events and test_events #1314
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
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.
i'm not sure if asserts are more appropriate for this situation? these are not invariants, it's more argument checking, so i think raising TypeErrors might be better (although the error messages could be improved)
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.
Do our users call
subscribe
? It seems to me that subscribing to an event is an internal thing and the events are exposed to users only through plugins/detectors.If it is internal - then having an assertion here should be good enough ( ? ).
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.
you're right, generally users should opt for the Plugin/Detector interface rather than using the raw subscribe one. however, i'm not sure whether this is an external or internal interface matters too much; imo, it's more about whether the condition being checked is an invariant or for input error checking. in this case, it seems more for error checking, and
TypeError
actually seems like a more semantically correct and descriptive exception to raise, since this is actually a type checkThere 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.
Honestly I think that in the end ("in a production build") such checks are not needed (the code itself should never call this with bad type) but it is good to have it as a defence against ourselves when making changes. This way, having it as assertion is better, at least in theory (I wonder if there is a way to ship code without assertions in Python).
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.
yeah, I see your point. i think for this particular case it doesn't matter too much, i don't think
subscribe
is in any hot code paths. at the end of the day i think i do slightly prefer the TypeError since it is more specific, and from what i can see, having it shouldn't affect performance in a noticeable way. but it's only a slight preference :)