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
set_cell('something')
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 
documented?

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

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30486>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to