finding abc's

lars van gemerden lars at
Fri Jan 25 18:40:49 CET 2013

Hi all,

i was writing a function to determine the common base class of a number classes:

def common_base(classes):
    if not len(classes):
        return None
    common = set(classes.pop().mro())
    for cls in classes:
    while len(common) > 1:
        cls1 = common.pop()
        cls2 = common.pop()
        if issubclass(cls1, cls2):
        elif issubclass(cls2, cls1):
    return common.pop()

and ran common_base(int, float), hoping to get numbers.Number.

this did not work because abstract base classes are not always in the mro() of classes.

My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)?

Cheers, Lars 

More information about the Python-list mailing list