[Python-ideas] The Descriptor Protocol...

Nick Coghlan ncoghlan at gmail.com
Thu Mar 3 13:23:40 CET 2011

On Thu, Mar 3, 2011 at 10:12 PM, Andrew Svetlov
<andrew.svetlov at gmail.com> wrote:
>> Not a bad idea at all, although I would use "as" for the purpose (it's
>> already a keyword we use for funny not-quite-assignment operations).
> "as" is definitely better.
> But in
>> class Person:
>>  name as n = Str(n)
> we still can see name duplication.

However, compared to the status quo:

1. The backreference can use an arbitrarily short name, as it won't
form part of the API*
2. This can be designed so the compiler helps out in detecting typos
3. If you later decide to change the public name (the real bane of the
repeat-as-a-string workaround), it only needs to be changed in one

*This can actually be done by using a pre-AST transform, such that the
"n" variable never appears in the AST, instead being replaced by the
constant string "name"

I don't personally believe the use case is frequent enough to justify
the complexity of a whole new statement type, but it's an interesting
idea to consider regardless.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list