__bases__ misleading error message

Mario Figueiredo marfig at gmail.com
Sat Jan 24 05:16:26 EST 2015


Consider the following code at your REPL of choice

        class Super:
            pass

        class Sub:
            pass

        foo = Sub()

        Sub.__bases__
        foo.__bases__

The last statement originates the following error:

        AttributeError: 'Sub' object has no attribute '__bases__'

Naturally the 'Sub' object has an attribute __bases__. It's the instance 
that has not. So shouldn't the error read like:

        AttributeError: 'Sub' instance has no attribute '__bases__', or
        AttributeError: 'foo' object has no attribute '__bases__'





More information about the Python-list mailing list