__bases__ misleading error message

Terry Reedy tjreedy at udel.edu
Sat Jan 24 19:55:18 EST 2015


On 1/24/2015 4:51 PM, Marco Buttu wrote:
> On 24/01/2015 20:24, Terry Reedy wrote:
>>> On 1/24/2015 5:16 AM, Mario Figueiredo wrote:
>>>>>> Consider the following code at your REPL of choice
>>>>> class Sub:
>>> pass
>>>>>> foo = Sub()
>>>>>> Sub.__bases__
>>> foo.__bases__
>>>>>> The last statement originates the following error:
>>>> This is an anomalous situation.

'This situation' being that Someclass.attro works but Someclass().attro 
raises.
 Normally, if a class has an attribute,
In other words, if 'Someclass.attro' evaluates to an object
>> instances have the same attribute

then 'Someclass().attro' *normally* evaluates to the same object
>> (unless overriden).

(unless 'Someclass().attro' has been bound to a different object)
because attribute lookup on an instance reverts to attribute lookup on 
the class and even its super classes (__bases__). Someclass.__bases__ 
is special; it is not listed by dir(Someclass), and it is not accessible 
via an instance.
> That is not true:

What I said, as I meant it to be understood, is true.
-- 
Terry Jan Reedy


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /