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

Michael Hudson mwh at python.net
Thu Feb 19 05:58:26 EST 2004


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?

> 	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!

> 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.

Cheers,
mwh

-- 
     ARTHUR:  Why are there three of you?
  LINTILLAS:  Why is there only one of you?
     ARTHUR:  Er... Could I have notice of that question?
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 11



More information about the Python-Dev mailing list