# HG changeset patch # User aurelien@trantor.local # Date 1258919241 -3600 # Sun Nov 22 20:47:21 2009 +0100 # Node ID 74ee8ba4f22eeb0bec510d1c6ee818ae2a4ff1bd # Parent 95e622fb42ab6e6dd9e288219f519a1267ae52d6 remove unused table element diff --git a/dispatch.py b/dispatch.py --- a/dispatch.py +++ b/dispatch.py @@ -1,3 +1,5 @@ +from operator import mul + def proximity(klass, mro): return mro.index(klass) @@ -5,7 +7,7 @@ "Use dispatch ranking similar to CLOS" # Schwartzian transform to weight match sigs, left-to-right" mros = [klass.mro() for klass in signature] - for (sig,func,nm),i in zip(matches,xrange(1000)): + for (sig,func),i in zip(matches,xrange(1000)): matches[i] = (map(proximity, sig, mros), matches[i]) matches.sort() return map(lambda t:t[1], matches) @@ -26,11 +28,10 @@ return func(*args) def add_rule(self, signature, func): - self._table.append((signature, func, 0)) + self._table.append((signature, func)) def linearize_table(self, signature): - from operator import mul - table = [(s,f,nm) for s,f,nm in self._table + table = [(s,f) for s,f in self._table if len(s) == len(signature) and reduce(mul, map(issubclass, signature, s))] if not table: @@ -38,6 +39,6 @@ raise TypeError("%s: no defined call signature <%s> for args (%s)" % (self.__class__.__name__, ",".join([str(o) for o in signature]), a)) - return [(nomatch,0)] + return [(nomatch,)] return map(lambda l:l[1:], lexicographic_mro(signature, table))