Issue 1416: @prop.setter decorators - Python tracker (original) (raw)

Created on 2007-11-10 05:58 by gvanrossum, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
propset.diff gvanrossum,2007-11-10 05:58
propset2.diff gvanrossum,2007-11-10 18:29
propset3.diff gvanrossum,2007-11-10 21:16
propset4.diff christian.heimes,2007-11-10 21:32
Messages (6)
msg57345 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-10 05:58
Here's an implementation of the idea I floated recently on python-dev (Subject: Declaring setters with getters). This implements the kind of syntax that I believe won over most folks in the end: @property def foo(self): ... @foo.setter def foo(self, value=None): ... There are also .getter and .deleter descriptors. This includes the hack that if you specify a setter but no deleter, the setter is called without a value argument when attempting to delete something. If the setter isn't ready for this, a TypeError will be raised, pretty much just as if no deleter was provided (just with a somewhat worse error message :-). I intend to check this into 2.6 and 3.0 unless there is a huge cry of dismay. Docs will be left to volunteers as always.
msg57354 - (view) Author: Paul Pogonyshev (_doublep) Date: 2007-11-10 15:45
Looks great (regardless of how this is implemented). I always hated this def get_foo / def set_foo / foo = property (get_foo, set_foo).
msg57356 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-10 18:29
propset2.diff is a new version that improves upon the heuristic for making the deleter match the setter: when changing setters, if the old deleter is the same as the old setter, it will replace both the deleter and setter. This diff is relative to the 2.6 trunk; it applies to 3.0 too.
msg57358 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-10 21:16
propset3.diff removes the hack that makes the deleter equal to the setter when no separate deleter has been specified. If you want a single method to be used as setter and deleter, write this: @foo.setter @foo.deleter def foo(self, value=None): ...
msg57359 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-10 21:32
Fixed a typo: +PyDoc_STRVAR(getter_doc, + "Descriptor to change the setter on a property."); ^^^
msg57361 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-10 22:13
Checked into trunk as revision 58929.
History
Date User Action Args
2022-04-11 14:56:28 admin set github: 45757
2007-11-10 22:13:02 gvanrossum set status: open -> closedresolution: acceptedmessages: +
2007-11-10 21:32:40 christian.heimes set files: + propset4.diffnosy: + christian.heimesmessages: +
2007-11-10 21:16:57 gvanrossum set files: + propset3.diffmessages: +
2007-11-10 18:29:03 gvanrossum set files: + propset2.diffmessages: +
2007-11-10 15:45:40 _doublep set nosy: + _doublepmessages: +
2007-11-10 05:58:10 gvanrossum create