[Python-ideas] inspect.getclassdistance

Chris Angelico rosuav at gmail.com
Mon Jan 5 15:47:55 CET 2015


On Tue, Jan 6, 2015 at 1:43 AM, Alexis Lee <alexisl at hp.com> wrote:
> Chris Angelico said on Mon, Jan 05, 2015 at 11:30:28PM +1100:
>> def bfs_bases(cls):
>>     """Yield the base which are belong to us"""
>>     yield from cls.__bases__
>>     for cls in cls.__bases__:
>>         yield from bfs_bases(cls)
>
> Much as I appreciate the pun, that isn't properly breadth-first, alas.

Hmm, good point. Once it's done one level (this class's bases), it
then goes on to recurse depth-first. Whoops. Buggy. Your version's
roughly as short, though, which was what I was aiming for - to point
out how trivially simple this could be.

ChrisA


More information about the Python-ideas mailing list