[Python-Dev] Declaring setters with getters
Tony Lownds
tony at PageDNA.com
Thu Nov 1 19:26:52 CET 2007
On Nov 1, 2007, at 10:26 AM, glyph at divmod.com wrote:
> This is a minor nit, as with all decorators that take an argument,
> it seems like it sets up a hard-to-debug error condition if you were
> to accidentally forget it:
>
> @property
> def foo(): ...
> @property.set
> def foo(): ...
>
> would leave you with 'foo' pointing at something that wasn't a
> descriptor at all. Is there a way to make that more debuggable?
How about this: give the property instance a method that changes a
property from read-only to read-write.
No parens, no frame magic. As a small bonus, the setter function would
not have to be named the same as the
property.
class A(object):
@property
def foo(self):
return 1
@foo.setter
def set_foo(self, value):
print 'set:', value
-Tony
More information about the Python-Dev
mailing list