The following code does not work, and may be a potential bug:
>>> def f():
def g(): return g
return g
>>> import cloudpickle; cloudpickle.dumps(f())
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import cloudpickle; cloudpickle.dumps(f())
File "cloudpickle.py", line 629, in dumps
cp.dump(obj)
File "cloudpickle.py", line 111, in dump
raise pickle.PicklingError(msg)
PicklingError: Could not pickle object as excessively deep recursion required.
Is it possible to fix this, or is this a fundamental limitation of closures in Python that cannot be worked around?