[Python-Dev] Descriptor API

Gonçalo Rodrigues op73418@mail.telepac.pt
Wed, 21 May 2003 01:41:16 +0100


I was doing some tricks with metaclasses and descriptors in Python 2.2 and
stumbled on the following:

>>> class test(object):

...             a = property(lambda: 1)

...

>>> print test.a

<property object at 0x01504D20>

>>> print test.a.__set__

<method-wrapper object at 0x01517220>

>>> print test.a.fset

None



What this means in practice, is that if I want to test if a descriptor is
read-only I have to have two tests: One for custom descriptors, checking
that getting __set__ does not barf and another for property, checking that
fset returns None.



So, why doesn't getting __set__  raise AttributeError in the above case?



Is this a bug? If it's not, it sure is a (minor) feature request from my
part :-)



With my best regards,

G. Rodrigues