>
>> Then why wasn't __class__ added to c.__dict__ ? Looks like namespace
>> searching to me.
>
> No, as you conclude later, __class__ is special, so you can still
> assign
> to __class__ even when __slots__ is defined because it's not
> considered
> a normal attribute. But note that __class__
Samuel M. Smith wrote:
> If you would care to elaborate on the how the lookup differs with
> method descriptor it would be most appreciated.
For the more authoritative guide, see:
http://users.rcn.com/python/download/Descriptor.htm
The basic idea is that a descriptor is an object that sits
>
>
> P.S. Note that there is an additional complication resulting from the
> fact that functions are descriptors:
>
class C(dict):
> ... pass
> ...
C.__iter__
>
C().__iter__
>
>
> Even though the C instance is accessing the __iter__ function on the
> class, it gets back a diff
Samuel M. Smith wrote:
> On 06 Dec, 2005, at 20:53, Steven Bethard wrote:
>> You can always shadow class-level attributes in the instance dict.
>> (That's what you were doing.) If you want to (try to) replace an
>> attribute in the class dict, you need to use the class object, not an
>> instance o
On 06 Dec, 2005, at 20:53, Steven Bethard wrote:
> Samuel M. Smith wrote:
>> The dict class has some read only attributes that generate an
>> exception
>> if I try to assign a value to them.
>> I wanted to trap for this exception in a subclass using super but it
>> doesn't happen.
>>
>> class
Samuel M. Smith wrote:
> The dict class has some read only attributes that generate an exception
> if I try to assign a value to them.
> I wanted to trap for this exception in a subclass using super but it
> doesn't happen.
>
> class SD(dict):
>pass
>
[snip]
> s = SD()
> super(SD,s).__set
Even more strangeness
If I define the class to use slots
class SD(dict):
__slots__ = ['a','b']
s = SD()
>>> s.__iter__
>>> s.__iter__ = 5
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: 'SD' object attribute '__iter__' is read-only
Then I get the read only
I have been playing around with a subclass of dict wrt a recipe for
setting dict items using attribute syntax.
The dict class has some read only attributes that generate an
exception if I try to assign a value to them.
I wanted to trap for this exception in a subclass using super but it
doesn