[PEAK] dispatch.strategy.dispatch_by_subclass bug

Radek Kanovsky rk at dat.cz
Fri Jan 28 10:25:13 EST 2005


The last print raises ``KeyError: <type 'object'>''

    from peak.core import *
    from dispatch.strategy import default

    [dispatch.generic()]
    def gm (t) : pass

    [gm.when(default)]
    def gm (t) : return 'default'

    [gm.when('issubclass(t,int)')]
    def gm2 (t) : return 'int'

    print gm(int)
    print gm(object)
    print gm(float)

I have checked implementation against my draft and they are the same
except one extra line in dispatch_by_subclass() in PEAK src.
If problematic line is removed, everything works as expected.

    def dispatch_by_subclass(ob,table):
        if isinstance(ob,ClassTypes):
            while 1:
                if ob in table:
                    return table[ob]
                try:
                    ob, = ob.__bases__
                    return table[ob]    # problematic line
                except ValueError:
                    if ob.__bases__:
                        return table.reseed(ob)
                    break
        return table[None]


RadekK



More information about the PEAK mailing list