[Python-Dev] Property syntax (Re: [Python-Dev] Extended Function syntax)

David Goodger goodger@python.org
Fri, 31 Jan 2003 11:16:49 -0500


[Guido van Rossum]
>>> Actually I was attempting to find a solution not just for
>>> properties but for other situations as well.  E.g. someone might
>>> want to define capabilities, or event handlers, or ...

[Greg Ewing]
>> But anyway, here's another idea:
>> 
>>   def foo as property:
>>     def __get__(self):
>>       ...
>>     def __set__(self, x):
>>       ...

[Guido van Rossum]
> I don't like things that reuse 'def', unless the existing 'def'
> is a special case and not just an alternative branch in the grammar.

I think Greg's idea ("as" or "is") could satisfy these conditions well
(generic solution, and unadorned "def" as special case).

A standard function definition (simple, unadorned "def") is
equivalent to:

    def f as function:
        suite

A standard method definition is as above, or if a distinction is
required or useful it could be equivalent to:

    def m(self) as method:
        suite

This syntax could be used to remove a recent wart, making generators
explicit:

    def g as generator:
        suite

Of course, it would be a syntax error if the generator suite didn't
contain a "yield" statement.

This syntax has aesthetic appeal.  I know nothing about its
implementability.  What namespace these new modifier terms would live
in, I also don't know.  The syntax proposal reads well and seems like
it could be a good general-purpose solution.

+1

-- David Goodger    http://starship.python.net/~goodger

Programmer/sysadmin for hire: http://starship.python.net/~goodger/cv