Skip to content

_PyFunction_FromConstructor doesn't support closures #92173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
larryhastings opened this issue May 2, 2022 · 3 comments
Closed

_PyFunction_FromConstructor doesn't support closures #92173

larryhastings opened this issue May 2, 2022 · 3 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@larryhastings
Copy link
Contributor

Bug report

_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.

Your environment

  • CPython versions tested on: main
  • Operating system and architecture: linux
@larryhastings larryhastings added the type-bug An unexpected behavior, bug, or error label May 2, 2022
@larryhastings larryhastings self-assigned this May 2, 2022
@larryhastings
Copy link
Contributor Author

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.

@larryhastings
Copy link
Contributor Author

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?

@MatthieuDartiailh
Copy link
Contributor

This looks like it has been addressed in #92175, should the issue be closed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants