[issue14369] make __closure__ writable

Nick Coghlan report at bugs.python.org
Wed Oct 11 22:46:41 EDT 2017


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Thinking about the interaction between this idea and https://bugs.python.org/issue30744 made me realise that there's a subtlety here that would probably need to be spelled out more clearly in the docs for __closure__ than it is for __code__: any changes made to a function object (whether it's a synchronous function, a generator, or a coroutine) will only affect *future* function invocations, as execution frames capture references to both the code object and all the closure cells when they're created.

(Thought prompted by asking myself "What would happen to existing generator-iterators if you rebound the closure on the generator function?". The answer is "Nothing", but I figure if I had to think about it, that answer likely isn't going to be obvious to folks that are less familiar with how the eval loop works in practice)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue14369>
_______________________________________


More information about the Python-bugs-list mailing list