Arrange the given list of classes into a hierarchy of nested lists. Where a nested list appears, it contains classes derived from the class whose entry immediately precedes the list. Each entry is a 2-tuple containing a class and a tuple of its base classes. If the 'unique' argume
(classes, unique=False)
| 1173 | return results |
| 1174 | |
| 1175 | def getclasstree(classes, unique=False): |
| 1176 | """Arrange the given list of classes into a hierarchy of nested lists. |
| 1177 | |
| 1178 | Where a nested list appears, it contains classes derived from the class |
| 1179 | whose entry immediately precedes the list. Each entry is a 2-tuple |
| 1180 | containing a class and a tuple of its base classes. If the 'unique' |
| 1181 | argument is true, exactly one entry appears in the returned structure |
| 1182 | for each class in the given list. Otherwise, classes using multiple |
| 1183 | inheritance and their descendants will appear multiple times.""" |
| 1184 | children = {} |
| 1185 | roots = [] |
| 1186 | for c in classes: |
| 1187 | if c.__bases__: |
| 1188 | for parent in c.__bases__: |
| 1189 | if parent not in children: |
| 1190 | children[parent] = [] |
| 1191 | if c not in children[parent]: |
| 1192 | children[parent].append(c) |
| 1193 | if unique and parent in classes: break |
| 1194 | elif c not in roots: |
| 1195 | roots.append(c) |
| 1196 | for parent in children: |
| 1197 | if parent not in classes: |
| 1198 | roots.append(parent) |
| 1199 | return walktree(roots, children, None) |
| 1200 | |
| 1201 | # ------------------------------------------------ argument list extraction |
| 1202 | Arguments = namedtuple('Arguments', 'args, varargs, varkw') |