bpo-34635: inspect: add tools for subclasses by ioistired · Pull Request #9186 · python/cpython (original) (raw)
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation3 Commits7 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Adds inspect.getsubclasses, inspect.getallsubclasses (recursive), and inspect.getsubclasstree (recursive, maintains structure).
See documentation for more details.
https://bugs.python.org/issue34635
Hello, and thanks for your contribution!
I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).
Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.
You can check yourself to see if the CLA has been received.
Thanks again for your contribution, we look forward to reviewing it!
here is a sample method that pretty prints a SubclassNode:
def pformat(self, _indent_level=1): out = '{0.module}.{0.qualname}'.format(self.cls)
for child in self.children:
out += '\n' + '\t' * _indent_level + child.pformat(_indent_level+1)
return out
class A: pass class B(A): pass class C(A): pass class D(B, C): pass class E(A): pass class F(B): pass print(inspect.getsubclasstree(A).pformat()) main.A main.B main.D main.F main.C main.D main.E