Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Setter Propertys' mro?

Reply
Thread Tools

Setter Propertys' mro?

 
 
cipher
Guest
Posts: n/a
 
      09-07-2008
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

>>> class test:

.... def _test(self):
.... return 4
.... def _stest(self)ass # dont change value
.... def _dtest(self,value)ass
.... p=property(_test,_stest,_dtest)
>>> t=test()
>>> t.p

4
>>> t.p=5
>>> t.p

5

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

>>> t.__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)ass # dont change value
def _dtest(self)ass
p=property(_test,_stest,_dtest)
>>> t=test()
>>> t.p

4
>>> t.p=5
>>> t.p

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.

--
Cipher
 
Reply With Quote
 
 
 
 
Tommy Grav
Guest
Posts: n/a
 
      09-07-2008
On Sep 6, 2008, at 9:15 PM, cipher wrote:

> 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
>
>>>> class test:


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

Cheers
Tommy
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      09-07-2008
On Sat, 06 Sep 2008 18:15:33 -0700, cipher wrote:

> 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
>
>>>> class test:



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.



--
Steven
 
Reply With Quote
 
cipher
Guest
Posts: n/a
 
      09-07-2008
On Sep 6, 9:10*pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> On Sat, 06 Sep 2008 18:15:33 -0700, cipher wrote:
> > 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

>
> >>>> class test:

>
> 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.
>
> --
> Steven


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataBinder setter method. =?Utf-8?B?VHUtVGhhY2g=?= ASP .Net 0 03-15-2005 11:23 PM
Static fields accessed by getter/setter...what happens? Stacey Java 1 02-10-2004 02:28 PM
Tired of 100s of stupid Getter/Setter methods Timo Nentwig Java 75 01-18-2004 05:17 AM
JSP taglib: Unable to find setter method for attribute kaeli Java 5 01-05-2004 07:15 PM
May I do data type conversion within getter/setter? Raoul Markus Java 3 09-20-2003 06:30 PM



Advertisments