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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-34635: inspect: add tools for subclasses #9186

Closed
wants to merge 7 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@bmintz

bmintz commented Sep 11, 2018

Adds inspect.getsubclasses, inspect.getallsubclasses (recursive), and inspect.getsubclasstree (recursive, maintains structure).

See documentation for more details.

https://bugs.python.org/issue34635

@the-knights-who-say-ni

This comment has been minimized.

Show comment
Hide comment
@the-knights-who-say-ni

the-knights-who-say-ni Sep 11, 2018

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!

the-knights-who-say-ni commented Sep 11, 2018

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!

@bmintz

This comment has been minimized.

Show comment
Hide comment
@bmintz

bmintz Sep 11, 2018

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

bmintz commented Sep 11, 2018

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
@bmintz

This comment has been minimized.

Show comment
Hide comment
@bmintz

bmintz commented Sep 14, 2018

@bmintz bmintz closed this Sep 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment