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)
| 1197 | return results |
| 1198 | |
| 1199 | def getclasstree(classes, unique=False): |
| 1200 | """Arrange the given list of classes into a hierarchy of nested lists. |
| 1201 | |
| 1202 | Where a nested list appears, it contains classes derived from the class |
| 1203 | whose entry immediately precedes the list. Each entry is a 2-tuple |
| 1204 | containing a class and a tuple of its base classes. If the 'unique' |
| 1205 | argument is true, exactly one entry appears in the returned structure |
| 1206 | for each class in the given list. Otherwise, classes using multiple |
| 1207 | inheritance and their descendants will appear multiple times.""" |
| 1208 | children = {} |
| 1209 | roots = [] |
| 1210 | for c in classes: |
| 1211 | if c.__bases__: |
| 1212 | for parent in c.__bases__: |
| 1213 | if parent not in children: |
| 1214 | children[parent] = [] |
| 1215 | if c not in children[parent]: |
| 1216 | children[parent].append(c) |
| 1217 | if unique and parent in classes: break |
| 1218 | elif c not in roots: |
| 1219 | roots.append(c) |
| 1220 | for parent in children: |
| 1221 | if parent not in classes: |
| 1222 | roots.append(parent) |
| 1223 | return walktree(roots, children, None) |
| 1224 | |
| 1225 | # ------------------------------------------------ argument list extraction |
| 1226 | Arguments = namedtuple('Arguments', 'args, varargs, varkw') |