[Python-Dev] Declaring setters with getters
glyph at divmod.com
glyph at divmod.com
Thu Nov 1 18:26:52 CET 2007
On 02:01 pm, guido at python.org wrote:
>On 10/31/07, glyph at divmod.com <glyph at divmod.com> wrote:
>>As long as we're all tossing out ideas here, my 2ยข. I vastly prefer
>>this:
>> >> @property.set
>>to this:
>> > @property.set(attribute)
>I don't approve of it. It has always been and will always
>continue to be my position that these are semantically unkosher,
>because it means that you can't wrap them in convenience functions or
>invoke them in different contexts, and that means that the semantics
>are hard to explain.
Point taken.
>If you really want another argument, repeating the property name
>actually does have an additional use case: you can have a read-only
>property with a corresponding read-write property whose name differs.
I don't actually have this use-case, but it does make the actual
semantics of the provided argument a bit clearer to me. It's not an
implementation detail of fusing the properties together, it's just
saying which property to get the read accessor from.
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?
More information about the Python-Dev
mailing list