How to create new closure cell objects?
问题 I need to monkey-patch my library to replace an instance of a symbol, and it's getting referenced by some function closures. I need to copy those functions (since I also need access to original unpatched version of the function as well), but __closure__ is immutable, and I can't copy.copy it, so how can I create new closure cells objects in Python 2.7? I for example given this function def f(): def incorrectfunction(): return 0 def g(): return incorrectfunction() return g def correctfunction(