You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
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:
Activity
gvanrossum commentedon Nov 10, 2007
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:
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.
doublep commentedon Nov 10, 2007
Looks great (regardless of how this is implemented). I always hated this
def get_foo / def set_foo / foo = property (get_foo, set_foo).
gvanrossum commentedon Nov 10, 2007
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.
gvanrossum commentedon Nov 10, 2007
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:
tiran commentedon Nov 10, 2007
Fixed a typo:
+PyDoc_STRVAR(getter_doc,
+ "Descriptor to change the setter on a property.");
^^^
gvanrossum commentedon Nov 10, 2007
Checked into trunk as revision 58929.