Terry J. Reedy added the comment:

A possible counter-indication would be if setting a cell could cause a crash, 
as opposed to a mysterious exception.  Since 3.x already allows writing any 
object to a cell from python code,
def outer():
    cell = None
    def inner(ob):
        nonlocal cell
        cell = ob  # rebinds <hidden-cell>.cell_contents
    return inner

set_cell = outer()
print(set_cell.__closure__[0].cell_contents)  # None
print(set_cell.__closure__[0].cell_contents)  # 'something'

making "cell.cell_contents = 'something'" legal should not enable more crashes.

I think that "function.__closure__[i].cell_contents = object" is perhaps not a 
good idea for production code, but I think it falls within the realm of 
'consenting adults code' for the other uses suggested above.  How should it be 

nosy: +terry.reedy
stage: needs patch -> patch review

Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to