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' a
(classes, unique=False)
| 1270 | return results |
| 1271 | |
| 1272 | def getclasstree(classes, unique=False): |
| 1273 | """Arrange the given list of classes into a hierarchy of nested lists. |
| 1274 | |
| 1275 | Where a nested list appears, it contains classes derived from the class |
| 1276 | whose entry immediately precedes the list. Each entry is a 2-tuple |
| 1277 | containing a class and a tuple of its base classes. If the 'unique' |
| 1278 | argument is true, exactly one entry appears in the returned structure |
| 1279 | for each class in the given list. Otherwise, classes using multiple |
| 1280 | inheritance and their descendants will appear multiple times.""" |
| 1281 | children = {} |
| 1282 | roots = [] |
| 1283 | for c in classes: |
| 1284 | if c.__bases__: |
| 1285 | for parent in c.__bases__: |
| 1286 | if parent not in children: |
| 1287 | children[parent] = [] |
| 1288 | if c not in children[parent]: |
| 1289 | children[parent].append(c) |
| 1290 | if unique and parent in classes: break |
| 1291 | elif c not in roots: |
| 1292 | roots.append(c) |
| 1293 | for parent in children: |
| 1294 | if parent not in classes: |
| 1295 | roots.append(parent) |
| 1296 | return walktree(roots, children, None) |
| 1297 | |
| 1298 | # ------------------------------------------------ argument list extraction |
| 1299 | Arguments = namedtuple('Arguments', 'args, varargs, varkw') |