You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_PyFunction_FromConstructor doesn't support closures #92173
_PyFunction_FromConstructor creates a PyFunctionObject, populating its fields by pulling them from a PyFrameConstructor object. But it ignores the fc_closure field, which means it always creates a function that has no closure. Creating functions with closures is a totally legitimate use case and this is just a bug.
PyEval_EvalCodeEx populates the fc_closure field with the closure argument passed in. CPython doesn't itself use PyEval_EvalCodeEx, it's a "legacy API". But it's an externally visible and supported API call.
Unfortunately, there's no straightforward way to test this change right now. I'm in the process of adding a use of PyEval_EvalCodeEx (adding support for a closure argument to exec) but that PR depends on fixing this bug first. So I'll make you a deal: my PR won't test this fix, but I'll test it in advance in my other PR, and that PR will add a test for this code path. Deal?
Activity
larryhastings commentedon May 2, 2022
PyEval_EvalCodeExpopulates thefc_closurefield with the closure argument passed in. CPython doesn't itself usePyEval_EvalCodeEx, it's a "legacy API". But it's an externally visible and supported API call.larryhastings commentedon May 2, 2022
Unfortunately, there's no straightforward way to test this change right now. I'm in the process of adding a use of
PyEval_EvalCodeEx(adding support for a closure argument toexec) but that PR depends on fixing this bug first. So I'll make you a deal: my PR won't test this fix, but I'll test it in advance in my other PR, and that PR will add a test for this code path. Deal?MatthieuDartiailh commentedon Jan 16, 2023
This looks like it has been addressed in #92175, should the issue be closed ?