FAQ
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):pass # dont change value
... def _dtest(self,value):pass
... 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):pass # dont change value
def _dtest(self):pass
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

Search Discussions

  • Tommy Grav at Sep 7, 2008 at 1:47 am

    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
  • Steven D'Aprano at Sep 7, 2008 at 4:10 am

    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
  • Cipher at Sep 7, 2008 at 4:50 am

    On Sep 6, 9:10?pm, Steven D'Aprano <st... at 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 7, '08 at 1:15a
activeSep 7, '08 at 4:50a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase