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 1 commit into from Dec 20, 2018

Conversation

Projects
None yet
2 participants
@disconnect3d
Copy link
Contributor

disconnect3d commented Dec 20, 2018

This change is Reviewable

@@ -139,22 +139,19 @@ def _publish_impl(self, _name, *args, **kwargs):
sink._publish_impl(_name, *args, **kwargs)

def subscribe(self, name, method):
if not inspect.ismethod(method):
raise TypeError
assert inspect.ismethod(method), f'{method.__class__.__name__} is not a method'

This comment has been minimized.

@mossberg

mossberg Dec 20, 2018

Contributor

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)

This comment has been minimized.

@disconnect3d

disconnect3d Dec 20, 2018

Contributor

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 ( ? ).

This comment has been minimized.

@mossberg

mossberg Dec 20, 2018

Contributor

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 check

This comment has been minimized.

@disconnect3d

disconnect3d Dec 20, 2018

Contributor

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).

This comment has been minimized.

@mossberg

mossberg Dec 20, 2018

Contributor

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 :)

@disconnect3d disconnect3d merged commit 4cb7e3b into master Dec 20, 2018

5 checks passed

codeclimate All good!
Details
codeclimate/total-coverage 70% (0.0% change)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details

@disconnect3d disconnect3d deleted the refactor-events branch Dec 20, 2018

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