[Python-Dev] Plea for function/method syntax sugar (PEP 318, with a different syntax)

Bob Ippolito bob at redivi.com
Thu Feb 19 11:00:01 EST 2004

On Feb 19, 2004, at 5:58 AM, Michael Hudson wrote:

> Bob Ippolito <bob at redivi.com> writes:
>> Some time ago, mwh developed a patch that adds some syntactical sugar
>> to def, which is equivalent to PEP 318 though it has a different and
>> more flexible syntax...
>> previous threads can be easily found here:
>> http://www.google.com/search?q=+site:mail.python.org+%22meth-syntax-
>> sugar%22
>> the latest version of mwh's patch is here:
>> http://starship.python.net/crew/mwh/hacks/meth-syntax-sugar-3.diff
>> Here's a quick overview:
> [snip]
>> What the patch doesn't do:
>> 	lambda is not allowed in the "sugary expressions list"
> Huh?  For a bunch of versions of the patch, putting lambda in the
> "sugary expressions list" made Python trip an assert, but I believe I
> fixed that in the most recent version.  Or do you mean something else?

Oh ok, it works, but lambda needs to go in parens.  Makes sense.  I 
tried it without parens first, thinking that the closing ] would be 
enough syntax for a single lambda to work, because it does for lists 
and function calls.

 >>> def foo(bar) [lambda a:a]:
   File "<stdin>", line 1
     def foo(bar) [lambda a:a]:
SyntaxError: invalid syntax
 >>> def foo(bar) [(lambda a:a)]:

>> 	there's no *expansion and it won't take an actual list so if
>> 	you want  a prebaked list of transformations then you'll have
>> 	to roll a callable  that does it such as:
>> def prebake(*expressions):
>>      def _prebake(fn):
>>          for transformation in expressions:
>>              fn = transformation(fn)
>>          return fn
>>      return fn
> I just don't understand what you mean here.
> You're contemplating
>     def foo() [memoize, *list_of_callables]:
>         ...
> Eugh!

I'm just saying.. not something I would use :)

>> This syntactical sugar for def is so unbelievably important to PyObjC
>> (and likely other projects) that I am willing to distribute my own
>> modified version of Python if it doesn't make 2.4 (though I would
>> probably use Stackless as the base, but that's another plea for
>> another  day).
>> The patch looks like it still applies to CVS HEAD, but there is a
>> little fuzz on hunk 2.  I have not tested it yet, but I have tested it
>> against CVS HEAD of the 2.3.3 based Stackless.
>> I'm willing to help however I can in order to get this into Python 
>> 2.4.
> PEP 306 is (intended to be) a checklist of what's needed.

Looks good.  I see "Certain changes may require tweaks to the library 
module pycblr", but google doesn't even know what or where that is.  
I'll go through it and make a new CVS HEAD patch as well as test 
additions and doc changes this weekend.  However, I'm not going to deal 
with Jython and I obviously can't do anything about pycblr :)


More information about the Python-Dev mailing list