[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Jim Jewett jimjjewett at gmail.com
Thu Sep 29 02:46:25 CEST 2011

On Wed, Sep 28, 2011 at 1:23 AM, Arnaud Delobelle <arnodel at gmail.com> wrote:

> A hybrid approach would be possible, taking from both approaches
> (decorator and keyword):
> * a keyword to declare in the body of the function that a variable is
> of the "own" kind.
> * function objects would grow an __own__ attribute which is a dict-like object:
>    - f.__own__["i"] would return the contents of the cell that the
> own variable "i" refers to
>    - f.__own__["i"] = 42 would set the cell contents of the own
> variable "i" to 42
> (or some other equivalent mechanism)
> * then one could create a kind of "inject" decorator.

Any reason not to just use the function itself, as opposed to a
designated dictionary?

Right now, we don't have a good way to refer to a function either
before it defined (decorator time) or while it is being defined, but
that seems like a subset of what you would need for the above
proposal.  (Of course, I did like the functionality of PEP 3130.)


More information about the Python-ideas mailing list