From fe84bfbbb6e80cedb1faffafb40e29642c94e669 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 29 Aug 2020 16:29:40 +0200 Subject: [PATCH] callbacks: add comments to findCallbacksForArgs. --- src/callbacks.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/callbacks.py b/src/callbacks.py index e309a2531..ddacf9a7f 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -775,14 +775,18 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): (a list of strings) and the plugins for which it was a command.""" assert isinstance(args, list) args = list(map(canonicalName, args)) + + # Find a list maxL such that maxL = args[0:n] for the largest n + # possible such that maxL is a command. cbs = [] maxL = [] for cb in self.irc.callbacks: if not hasattr(cb, 'getCommand'): continue L = cb.getCommand(args) - #log.debug('%s.getCommand(%r) returned %r', cb.name(), args, L) if L and L >= maxL: + # equivalent to "L and len(L) >= len(maxL)", because L and maxL + # are both "prefixes" of the same list. maxL = L cbs.append((cb, L)) assert isinstance(L, list), \ @@ -791,7 +795,11 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): 'getCommand must return a prefix of the args given. ' \ '(args given: %r, returned: %r)' % (args, L) log.debug('findCallbacksForArgs: %r', cbs) + + # Filter out all the entries in cbs that are smaller than maxL (ie. + # maxL contains them, with more items at the end.) cbs = [cb for (cb, L) in cbs if L == maxL] + if len(maxL) == 1: # Special case: one arg determines the callback. In this case, we # have to check, in order: