MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getclasstree

Function getclasstree

tools/python-3.11.9-amd64/Lib/inspect.py:1272–1296  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1270 return results
1271
1272def 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
1299Arguments = namedtuple('Arguments', 'args, varargs, varkw')

Callers

nothing calls this directly

Calls 2

walktreeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected