[Python-ideas] make __closure__ writable

Tim Delaney timothy.c.delaney at gmail.com
Thu Mar 29 01:58:19 CEST 2012

On 26 March 2012 11:32, Victor Stinner <victor.stinner at gmail.com> wrote:

> 2012/3/16 Yury Selivanov <yselivanov.ml at gmail.com>:
> > Can we make the __closure__ attribute writeable?  Since __code__ already
> is, ...
> I never understood why __code__ is writable. What is the usecase of
> modifying the code of an existing function?

There are many things you can do with bytecode manipulation (whether you
should is another question). Among other things, I've used it for
optimisation (e.g. my optimised self.super recipe that probably isn't
actually available online anymore). Instrumentation of code is another
thing, although these days you're probably better off using a decorator.

There aren't a lot of real use cases, but if nothing else it can be a lot
of fun :)

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120329/8758005c/attachment.html>

More information about the Python-ideas mailing list