Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37706

Re: finding abc's

Newsgroups comp.lang.python
Date 2013-01-25 16:48 -0800
References <766ec7eb-ab43-4c17-8073-3a0e6a8b89ea@googlegroups.com> <mailman.1052.1359140888.2939.python-list@python.org> <0d837f4c-c4a7-4df6-978c-b62a10ef9d70@googlegroups.com>
Subject Re: finding abc's
From lars van gemerden <lars@rational-it.com>
Message-ID <mailman.1066.1359161309.2939.python-list@python.org> (permalink)

Show all headers | View raw


for future reference, i decided to go with 2 functions:

def common_bases(classes):
    if not len(classes):
        return None
    common = set(classes.pop().mro())
    for cls in classes:
        common.intersection_update(cls.mro()) #all subclasses in common       
    return [cls for cls in common if not any(sub in common for sub in cls.__subclasses__())] #the classes of which no subclasses are present

def unique_common_base(classes):
    while len(classes) > 1:
        classes = common_bases(classes)
    return classes.pop()

if i tested and understood correctly, they only take classes in the mro() into account (which might include abc's), the first gives all common base classes, the second recursively reduces further to one single class (the latter might not make to much sense, but in my program it is a safe bet for rare cases).

Thanks again for the help,

Cheers, Lars

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 09:40 -0800
  Re: finding abc's Ian Kelly <ian.g.kelly@gmail.com> - 2013-01-25 12:04 -0700
    Re: finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 12:05 -0800
    Re: finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 12:05 -0800
  Re: finding abc's Peter Otten <__peter__@web.de> - 2013-01-25 20:08 +0100
    Re: finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 12:08 -0800
      Re: finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 16:48 -0800
      Re: finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 16:48 -0800
    Re: finding abc's lars van gemerden <lars@rational-it.com> - 2013-01-25 12:08 -0800

csiph-web