On Tue, Apr 13, 2010 at 12:15 PM, Hans Mulder <han...@xs4all.nl> wrote: > Steven D'Aprano wrote: >> Given a class C, is there some way to find out what classes >> issubclass(C, X) will return true for? Obviously you can get a partial >> list, by walking the MRO, but is there a list somewhere of which ABCs >> consider C a subclass? >> >> Presumably the general answer is No, because any class X could happen to >> have a __subclasscheck__ method that returns True when called with C. > > New style class method __subclasses__ that returns a list of the immediate > subclasses. By recursing down from object, you can make a list of all new > style classes in your current interpreter. Then use issubclass to find > the ones that consider themselves subclasses of C.
Being pedantic here, but your last statement is the wrong way around: C is the one who decides which classes should be considered its subclasses. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list