pre-PEP: Suite-Based Keywords
Brian Sabbey
sabbey at u.washington.edu
Sat Apr 16 16:58:38 EDT 2005
Shane Hathaway wrote:
> Kent Johnson wrote:
>> Brian Sabbey wrote:
>>> Using suite-based keyword arguments, the code
>>>
>>> f(x = 1)
>>>
>>> is equivalent to
>>>
>>> f():
>>> x = 1
>>
>>
>> ISTM the syntax is ambiguous. How do you interpret
>> if f():
>> x = 1
>> ?
>>
>> Is a suite alllowed only when a block could not be introduced in the
>> current syntax?
>
> I like this PEP a lot, but your concern is valid. Maybe Brian could
> modify the PEP slightly to disambiguate. How about using an ellipsis in
> the argument list to signify suite-based keywords? Examples:
>
> f(...):
> x = 1
>
> class C(object):
> x = property(...):
> doc = "I'm the 'x' property."
> def fget(self):
> return self.__x
> def fset(self, value):
> self.__x = value
> def fdel(self):
> del self.__x
>
> d = dict(...):
> a = 1
> b = 2
>
> Using an ellipsis in a statement that would begin a different kind of
> block is illegal and generates a syntax error. Note that this usage
> seems to fit well with the definition of "ellipsis".
>
> http://dictionary.reference.com/search?q=ellipsis
>
> Shane
Yes, my description of the syntax was ambiguous. To clarify, I intended
the syntax to be backwardly compatible. That is, one would not be able to
use a suite to define keywords if there already exists a suite for other
reasons. So, one would not be able to use a suite to pass keywords to 'f'
in this situation:
if f():
x = 1
This code should behave exactly as it does now.
I agree that the ellipsis idea probably makes the code more readable, and
it may be a good idea to have them for that reason. However, ellipses are
not necessary as a way to disambiguate the syntax; all statements
containing suites currently begin with a keyword, and keyword suites would
not.
-Brian
More information about the Python-list
mailing list