Skip to content

Commit ea5a5bf

Browse files
author
Omer Katz
authored
Extract creation of lookup key into a helper. (celery#4725)
1 parent 2636251 commit ea5a5bf

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

celery/utils/dispatch/signal.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ def _make_id(target): # pragma: no cover
3737
return id(target)
3838

3939

40+
def _make_lookup_key(receiver, sender, dispatch_uid):
41+
if dispatch_uid:
42+
return (dispatch_uid, _make_id(sender))
43+
else:
44+
return (_make_id(receiver), _make_id(sender))
45+
46+
4047
NONE_ID = _make_id(None)
4148

4249
NO_RECEIVERS = object()
@@ -173,10 +180,7 @@ def _connect_signal(self, receiver, sender, weak, dispatch_uid):
173180
)
174181
return receiver
175182

176-
if dispatch_uid:
177-
lookup_key = (dispatch_uid, _make_id(sender))
178-
else:
179-
lookup_key = (_make_id(receiver), _make_id(sender))
183+
lookup_key = _make_lookup_key(receiver, sender, dispatch_uid)
180184

181185
if weak:
182186
ref = weakref.ref
@@ -220,10 +224,8 @@ def disconnect(self, receiver=None, sender=None, weak=None,
220224
warnings.warn(
221225
'Passing `weak` to disconnect has no effect.',
222226
CDeprecationWarning, stacklevel=2)
223-
if dispatch_uid:
224-
lookup_key = (dispatch_uid, _make_id(sender))
225-
else:
226-
lookup_key = (_make_id(receiver), _make_id(sender))
227+
228+
lookup_key = _make_lookup_key(receiver, sender, dispatch_uid)
227229

228230
disconnected = False
229231
with self.lock:

0 commit comments

Comments
 (0)