PEP 309 - Built-in closure type (with tentative syntax proposal)

Beni Cherniavsky cben at
Wed Feb 12 06:01:31 CET 2003

On 2003-02-11, Christos TZOTZIOY Georgiou wrote:

> On Mon, 10 Feb 2003 21:42:57 +0000, rumours say that Peter Harris
> <scav at> might have written:
> >My proposal is for a built-in closure type for Python, and
> >a syntax for closure literals.
> Hm... perhaps static variables would be something more generic, a la:
> def function(args):
>     static:
>         c = 5
>         d = 7
>     # normal code follows here
Please don't.  Not like this.  The proposed syntax means that the current
assumption "a def's body is not executed at definition time" breaks and I
need to start inspecting all function bodies for ``static``.  Granted,
it's well visible as the first body line.  Still I find it disquieting
that you mark some code inside the function to actually not be part of it.
It would be better if you did something like (with better keyword names)::

    c = 5
    d = 7
    def function(args):
      "normal code follows here"

But you can already get these semantics with a sensible syntax:

  def closure:    # back to the subject :-)
    c = 5
    d = 7
    def function(args):
      "normal code follows here"
    return function
  function = closure()

while-we-are-at-pep-frenzy-how-about-rebounding-with-:=-ly y'rs__
Beni Cherniavsky <cben at>


More information about the Python-list mailing list