Package expedient :: Package common :: Package extendable :: Module inheritance
[hide private]
[frames] | no frames]

Module inheritance

source code

Created on Apr 29, 2010

Licensed under the MIT License


Author: Gabriel Genellina

Functions [hide private]
 
itersubclasses(cls)
Generator over all subclasses of a given class, in depth first order.
source code
Variables [hide private]
  __package__ = None
Function Details [hide private]

itersubclasses(cls)

source code 

Generator over all subclasses of a given class, in depth first order.

>>> list(itersubclasses(int)) == [bool]
True
>>> class A(object): pass
>>> class B(A): pass
>>> class C(A): pass
>>> class D(B,C): pass
>>> class E(D): pass
>>> 
>>> for cls in itersubclasses(A):
...     print(cls.__name__)
B
D
E
C
>>> # get ALL (new-style) classes currently defined
>>> [cls.__name__ for cls in itersubclasses(object)] #doctest: +ELLIPSIS
['type', ...'tuple', ...]