Collapse duplicate behavior in engine_namespace_handler
@@ -270,15 +270,10 @@ def _engine_namespace_handler(k, v):
elif '.' in k:
plugin, attrname = k.split('.', 1)
plugin = getattr(engine, plugin)
- if attrname == 'on':
- if v and hasattr(getattr(plugin, 'subscribe', None), '__call__'):
- plugin.subscribe()
- return
- elif (
- (not v) and
- hasattr(getattr(plugin, 'unsubscribe', None), '__call__')
- ):
- plugin.unsubscribe()
+ op = 'subscribe' if v else 'unsubscribe'
+ sub_unsub = getattr(plugin, op, None)
+ if attrname == 'on' and callable(sub_unsub):
+ sub_unsub()
return
setattr(plugin, attrname, v)
else:
