Created
July 2, 2014 20:53
-
-
Save harlowja/975533763a276bfe7fb2 to your computer and use it in GitHub Desktop.
This file contains 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
import a | |
class B(a.A): | |
pass | |
def itersubclasses(cls, _seen=None): | |
"""Generator over all subclasses of a given class in depth first order.""" | |
_seen = _seen or set() | |
subs = cls.__subclasses__() | |
for sub in subs: | |
if sub not in _seen: | |
_seen.add(sub) | |
yield sub | |
for sub in itersubclasses(sub, _seen): | |
yield sub | |
print list(itersubclasses(a.A)) | |
import other_thing | |
print list(itersubclasses(a.A)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment