pre-PEP: Suite-Based Keywords - syntax proposal

Ron radam2 at tampabay.rr.com
Tue Apr 19 18:40:54 EDT 2005


Kay Schluehr wrote:
> Steven Bethard wrote:
> 
> 
>>So the object of a "where" is then always an ordered dict?
> 
> 
> Yes.
> 
> 
>>If so, then
>>I guess I like this proposal best so far.
>>
>>However, it does seem to have the problem that you can't have any
>>additional local variables so, for example, list comprehensions are
>>probably not usable...
>>
>>Or can you still drop the argument to "where" and just use the names
>>directly?  E.g.:
>>
>>x = property(fget=fget, doc=doc) where:
>>     doc = "I'm the 'x' property."
>>     def fget(self):
>>         return self.__x
> 
> 
> I can't see why this shouldn't work?
> 
> The specifiers behind "where" are present to determine the matching
> behaviour. The order of a dict is caused by different specifiers i.e. a
> dict- or tuple-like specifier. If a specifier is not present only names
> can be matched regardless of a sequence and this is always possible
> because we still have a dict with names as keys.
> 
> What should not be possible are statements like this:
> 
>  x = property(a, b) where:
>       doc = "I'm the 'x' property."
>       def fget(self):
>           return self.__x
> 
> because there is no rule to match doc and fget onto a and b. In this
> case we would need specifiers:
> 
>  x = property(a, b)
>      where **a:
>         doc = "I'm the 'x' property."
>      where **b:
>         def fget(self):
>             return self.__x
> 
> Ciao,
> Kay


Just throwing in another slight variation to Kay's example here.

How about using ***name in the same way as *name, and **name are used? 
It extends the current argument options in a consistent manner and 'I 
believe' is easy to explain and visually says something different is 
happening here.

This builds on the already present arg, *arg, **arg,  and so why not a 
***arg to represent the 4th alternative, a suite?

You would also need to use it in the def statement as well, and probably 
would want to anyway if your argument suite is that long.

def property(***a, ***b):
     a:
         doc = "I'm the default 'x' property."
     b:
         def foo(arg):
		return arg
     return arg


x = property(***a, ***b)
     a:
          doc = "I'm the 'x' property."
     b:
          def fget(self):
              return self.__x


With the ***name syntax, making it's obvious it's different (a good 
thing), and you might be able to drop the 'with' or 'where'.

The (***name) == (name: suite) relationship may be useful in other 
places as well.

I'm not sure on the returns for the def above, just trying to make it 
more complete.  I presuming foo would be the default if 'b' isn't given 
in the function call. I suppose the ***b, and b: suite, in the function 
call can be optional.  Same for the ***a and a: suite.  By having them 
named, either one could be absent and the order could be swapped in the 
call if it makes it more readable.

Cheers,
Ron_Adam



More information about the Python-list mailing list