[Python-Dev] Declaring setters with getters
Barry Warsaw
barry at python.org
Thu Nov 1 18:23:26 CET 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Nov 1, 2007, at 10:01 AM, Guido van Rossum 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:
>>
>> On 02:43 am, steven.bethard at gmail.com wrote:
>>> On 10/31/07, Fred Drake <fdrake at acm.org> wrote:
>>
>>>> @property.set
>>>> def attribute(self, value):
>>>> self._ignored = value
>>
>> to this:
>>> @property.set(attribute)
>>> def attribute(self, value):
>>> self._ignored = value
>>
>> since I don't see any additional expressive value in the latter,
>> and it
>> provides an opportunity to make a mistake.
>
> I was expecting this would be brought up, but that just ain't gonna
> happen. If you don't repeat the name, the decorator has to root around
> in the surrounding scope, which is fraught with peril. Solutions based
> on sys._getframe() have been around for years (e.g. several the
> Cookbook recipes) and if I had approved of that technique I would have
> adopted one long ago.
It's also not as if you're writing some string value the second time,
so any typos in the name will be caught early on.
- -Barry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
iQCVAwUBRyoLjnEjvBPtnXfVAQKcHAQAt8cmfJa93nVMX4/cIUTzUvke2LMhiKbj
5auo/TlymK6GMrKCLSpIOVfxMboj0tf5RqL8oS72OS6w6K+jlBiVFRZPf0NQtO1s
WXsKDR/tw5B8iiTsoi8CRASsbEBetTrHIa5WqWqYbNk1sE7GNGTK4kIGoMd1txyp
IdhLvYSJK7Q=
=v4I7
-----END PGP SIGNATURE-----
More information about the Python-Dev
mailing list