how to

Python Type Utils

Jun 24, 2025
pythonpython-typelangstype
1 Minutes
52 Words

Inheritance tree

[tested-ok-and-copy-here]

1
def print_inheritance_tree(cls, indent='', last=True, is_root=True):
2
if is_root:
3
print(cls.__name__)
4
else:
5
connector = '└── ' if last else '├── '
6
print(indent + connector + cls.__name__)
7
indent += ' ' if last else '│ '
8
bases = cls.__bases__
9
for i, base in enumerate(bases):
10
is_last = i == (len(bases) - 1)
11
print_inheritance_tree(base, indent, is_last, is_root=False)
Article title:Python Type Utils
Article author:Julyfun
Release time:Jun 24, 2025
Copyright 2025
Sitemap