Setter Propertys' mro?

Discussion in 'Python' started by cipher, Sep 7, 2008.

  1. cipher

    cipher Guest

    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
     
    cipher, Sep 7, 2008
    #1
    1. Advertising

  2. cipher

    Tommy Grav Guest

    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
     
    Tommy Grav, Sep 7, 2008
    #2
    1. Advertising

  3. 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
     
    Steven D'Aprano, Sep 7, 2008
    #3
  4. cipher

    cipher Guest

    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
     
    cipher, Sep 7, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VanReenenc
    Replies:
    1
    Views:
    488
    VanReenenc
    Jul 2, 2006
  2. John Perks and Sarah Mount

    MRO problems with diamond inheritance?

    John Perks and Sarah Mount, May 1, 2005, in forum: Python
    Replies:
    13
    Views:
    610
    Michele Simionato
    May 3, 2005
  3. kjok

    Loading a User Control With Propertys

    kjok, Sep 28, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    133
  4. Herman Geovany Ayala Zúñiga

    Multiple Array Strings propertys

    Herman Geovany Ayala Zúñiga, Jul 12, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    118
    Herman Geovany Ayala Zúñiga
    Jul 12, 2006
  5. Andreas Schulze

    modify HttpMethod or HttpRequest propertys

    Andreas Schulze, Oct 28, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    211
    Dan Rogers
    Nov 18, 2004
Loading...

Share This Page