Setter Propertys' mro?

C

cipher

Whats the mro (method resolution order) of a setter property (__set__
on a descriptor).
i seem to be experiencing some weird issue with them.
for example
.... def _test(self):
.... return 4
.... def _stest(self):pass # dont change value
.... def _dtest(self,value):pass
.... p=property(_test,_stest,_dtest)5

Why is that being 'overridden' ( by that i mean that it is storing
that value in t's __dict__)
{'t': 5}

why DIDNT the setter get hit?
however, if i specify the metaclass in the class definition it works
just fine...

class test:
__metaclass__=type
def _test(self):
return 4
def _stest(self,value):pass # dont change value
def _dtest(self):pass
p=property(_test,_stest,_dtest)4

why do i have to set the __metaclass__ ? this seems like a bug?
i know that i probably shouldn't worry about this because if a
programmer does want to set my value and it causes an error, thats his
problem.... but this bothers me. whats the point of the __set__ method
then?


Thanks in advanced.
 
T

Tommy Grav

Whats the mro (method resolution order) of a setter property (__set__
on a descriptor).
i seem to be experiencing some weird issue with them.
for example

You have to use class test(object). Only new style classes accepts
properties.

Cheers
Tommy
 
S

Steven D'Aprano

Whats the mro (method resolution order) of a setter property (__set__ on
a descriptor).
i seem to be experiencing some weird issue with them. for example


Unless you're using Python 3, there's your problem right there. In Python
2.x, properties only work correctly for new style classes, not classic
classes. Change the above line to:

class Test(object): # by convention, classes start with Uppercase.

and all should work (or at least you'll discover new and exciting
different problems with your code).

however, if i specify the metaclass in the class definition it works
just fine...

class test:
__metaclass__=type

which is more or less the same as inheriting from object, except uglier.
 
C

cipher

Unless you're using Python 3, there's your problem right there. In Python
2.x, properties only work correctly for new style classes, not classic
classes. Change the above line to:

class Test(object):  # by convention, classes start with Uppercase.

and all should work (or at least you'll discover new and exciting
different problems with your code).



which is more or less the same as inheriting from object, except uglier.

Thanks to both of you!! that solved it.
i wonder why the getters would work fine though??
neways, wtf do i care :)


again, thank you both.

__
Cipher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top