Skip to content
3 changes: 2 additions & 1 deletion canopen/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def unsubscribe(self, can_id, callback=None):
if callback is None:
del self.subscribers[can_id]
else:
self.subscribers[can_id].remove(callback)
if callback in self.subscribers[can_id]:
self.subscribers[can_id].remove(callback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe the circumstances where raising a ValueError exception here would have caused problems?

If a non-registered callback is passed, that is clearly the caller's fault and I think it's correct to raise an exception in response. The main place where this function is used is in remove_network() on the nodes, which in turn gets called when deleting it from the network object. If it is part of the network, these callbacks have been recorded in the list previously, so no exception will be raised.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I removed this change.


def connect(self, *args, **kwargs):
"""Connect to CAN bus using python-can.
Expand Down