pre-PEP: Suite-Based Keywords
Brian Sabbey
sabbey at u.washington.edu
Sat Apr 16 17:02:32 EDT 2005
Bengt Richter wrote:
> On Fri, 15 Apr 2005 19:32:02 -0700, James Stroud <jstroud at mbi.ucla.edu> wrote:
>
>> I_vote_yes(James):
>> I_understand_what_it_does = True
>> Makes_code_formatting_way_more_managable_in_tough_cases = True
>> Makes_code_way_more_readable = True
>> To_cool = True
>>
>> On Friday 15 April 2005 04:45 pm, Brian Sabbey wrote:
>>> Here is a pre-PEP for what I call "suite-based keyword arguments". The
>>> mechanism described here is intended to act as a complement to thunks.
>>> Please let me know what you think.
>>>
> Kind of cool. If we had full lambdas aka as anonymous defs (def foo(...) with foo left out ;-)
> would this be concise sugar for the equivalents shown below your examples?
>
> (The rule for parsing the suite of an anonymous def is that the left column of the first non-space
> character of the first suite statement following the def(): becomes the suite indent reference,
> and a dedent to the left of that ends the def(): or a closing bracket not opened in the def(): suite
> also ends it. Otherwise it is standard suite indentation)
>
>>> Suite-Based Keyword Arguments
>>> -----------------------------
>>>
>>> Passing complicated arguments to functions is currently awkward in Python.
>>> For example, the typical way to define a class property winds up polluting
>>> the class's namespace with the property's get/set methods. By allowing
>>> keyword arguments to be defined in a suite following a function call,
>>> complicated arguments can be passed in a cleaner, easier way.
>>>
>>> Examples
>>> ========
>>>
>>> Using suite-based keyword arguments, the code
>>>
>>> f(x = 1)
>>>
>>> is equivalent to
>>>
>>> f():
>>> x = 1
>
> f(**def():
> x = 1
> return vars())
Yes, it seems it would just be sugar for full lambdas. Although, in this
example and the others, wouldn't you have to actually call the anonymous
function?
f(**(def():
x = 1
return vars())())
Otherwise it seems like you are trying to pass a function, not the
keywords the function returns.
One could, of course, also do the same with a named function:
def no_longer_anonymous():
x = 1
return vars()
f(**no_longer_anonymous())
-Brian
More information about the Python-list
mailing list