Skip to content

Commit e4ac0ce

Browse files
committed
Simplify cleanup logic in Network.unsubscribe().
1 parent 38d3836 commit e4ac0ce

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

canopen/network.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,10 @@ def unsubscribe(self, can_id, callback=None) -> None:
7575
If given, remove only this callback. Otherwise all callbacks for
7676
the CAN ID.
7777
"""
78-
if callback is None:
79-
del self.subscribers[can_id]
80-
else:
78+
if callback is not None:
8179
self.subscribers[can_id].remove(callback)
82-
# Remove empty list entry
83-
if not self.subscribers[can_id]:
84-
del self.subscribers[can_id]
80+
if not self.subscribers[can_id] or callback is None:
81+
del self.subscribers[can_id]
8582

8683
def connect(self, *args, **kwargs) -> Network:
8784
"""Connect to CAN bus using python-can.

0 commit comments

Comments
 (0)