Re: what is wrong with this property setter

2016-06-09 Thread Peter Otten
Nagy László Zsolt wrote: > >>> Yes, and more. That property will also have a get method! Is it >>> intentional? >> It's a logical effect of how the setter() method works. The above is >> syntactic sugar for >> >> def set_parent(...): >>... >> set_parent = parent.setter(set_parent) >> >> and p

Re: what is wrong with this property setter

2016-06-09 Thread Nagy László Zsolt
>> Yes, and more. That property will also have a get method! Is it >> intentional? > It's a logical effect of how the setter() method works. The above is > syntactic sugar for > > def set_parent(...): >... > set_parent = parent.setter(set_parent) > > and parent.setter() creates a new property

Re: what is wrong with this property setter

2016-06-09 Thread Peter Otten
Nagy László Zsolt wrote: > >>> @parent.setter >>> def set_parent(self, new_parent): >>> self._parent = new_parent >> This creates a settable property with the name "set_parent" and leaves >> the read-only property "parent" alone. > Yes, and more. That property will also have a ge

Re: what is wrong with this property setter

2016-06-09 Thread Nagy László Zsolt
>> @parent.setter >> def set_parent(self, new_parent): >> self._parent = new_parent > This creates a settable property with the name "set_parent" and leaves the > read-only property "parent" alone. Yes, and more. That property will also have a get method! Is it intentional? -- h

Re: what is wrong with this property setter

2016-06-09 Thread Peter Otten
Nagy László Zsolt wrote: > class Test: > def __init__(self): > self._parent = None > > @property > def parent(self): > return self._parent > > @parent.setter > def set_parent(self, new_parent): > self._parent = new_parent > > > p, c = Test(), Test()

Re: what is wrong with this property setter

2016-06-09 Thread Steven D'Aprano
On Thursday 09 June 2016 17:28, Nagy László Zsolt wrote: > class Test: Are you using Python 3 or 2? In Python 2, property doesn't work correctly with classes unless they inherit from object (directly or indirectly). > def __init__(self): > self._parent = None > > @property >

Re: what is wrong with this property setter

2016-06-09 Thread Mark Summerfield
On Thursday, June 9, 2016 at 8:28:47 AM UTC+1, Nagy László Zsolt wrote: > class Test: > def __init__(self): > self._parent = None > > @property > def parent(self): > return self._parent > > @parent.setter > def set_parent(self, new_parent): > self._pare

what is wrong with this property setter

2016-06-09 Thread Nagy László Zsolt
class Test: def __init__(self): self._parent = None @property def parent(self): return self._parent @parent.setter def set_parent(self, new_parent): self._parent = new_parent p, c = Test(), Test() c.parent = p >py -3 test.py Traceback (most recent c