Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python float class doesn't show up in class hierarchy unless "prodded"

If I use this function to print out a python class hierarchy for some reason the type "float" doesn't show up 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, then float shows up. Can anyone explain this odd behavior? Is there something lazy about some python classes? I'm wondering if it might be missing some other classes too.

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

tweak(float)
like image 351
Jay Billfinger Avatar asked Jun 04 '26 13:06

Jay Billfinger


1 Answers

It seems to be a problem with Python 2.6.1. float shows on my installations (2.6.4 and 2.7, both on Windows) and on other newer versions tested by Jay and samplebias.

I looked for something relevant in the CPython changelog, but I couldn't find anything that seems to be related.

like image 182
Boaz Yaniv Avatar answered Jun 06 '26 03:06

Boaz Yaniv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!