__bases__ misleading error message
tjreedy at udel.edu
Sat Jan 24 20:24:41 CET 2015
On 1/24/2015 5:16 AM, Mario Figueiredo wrote:
> Consider the following code at your REPL of choice
> class Sub:
> foo = Sub()
> The last statement originates the following error:
This is an anomalous situation. Normally, if a class has an attribute,
instances have the same attribute (unless overriden). But this does not
> AttributeError: 'Sub' object has no attribute '__bases__'
In this message, 'Sub' is an adjective, modifying 'object, not naming
it. If you attend to the last line of the traceback
which is an integral part of the total error message, the interpretation
of this exception message should be clear.
> AttributeError: 'Sub' instance has no attribute '__bases__',
'Sub' is an instance of 'type', so "'Sub' instance" could also be taken
to mean the class if the traceback were ignored. But that would also be
wrong. An attribute error for the class, such as "Sub.xyz" give a
message ending with
AttributeError: type object 'Sub' has no attribute 'xyz'
Terry Jan Reedy
More information about the Python-list