The pyat class float class does not appear in the class hierarchy, unless "prodded"

If I use this function to print out the python class hierarchy for any reason, the type "float" does not appear in the output.

def printHier(cls, indent = 0, tab = "  "):

    print "%s%s" % (tab*indent, cls.__name__)

    try:
        subclasses = cls.__subclasses__()
    except TypeError:
        subclasses = cls.__subclasses__(cls)

    subclasses.sort(key = lambda v: v.__name__)

    for subcls in subclasses:
        printHier(subcls, indent = indent + 1)

printHier(object)

If I define this additional function (below) and call it before calling the first, a pop-up message appears. Can anyone explain this weird behavior? Is there anything lazy regarding some python classes? I am wondering if it can also skip some other classes.

def tweak(cls):
    """
     for some reason "float" doesn't show up in hierarchy unless
     we "prod" it...
    """
    superclasses = cls.__mro__

tweak(float)
+3
source share
1 answer

, Python 2.6.1. float (2.6.4 2.7, Windows), , Jay samplebias.

- CPython, .

+4

All Articles