What is use case for calling exec() with a closure parameter?

What is use case for calling exec() with a closure parameter?

Is there a PEP for this feature?

You mean why can you pass in globals and locals?

So that the code is run with the required namespaces.

The issue that proposed adding the closure parameter doesn’t suggest a specific use case, except for a suggested use related to PEP 649 that’s not actually discussed in that PEP. There’s some discussion on the pull request. There may have been more discussion elsewhere.

1 Like

No. The question is about passing in a closure (nonlocals), not globals or locals.

See the upcoming documentation](Built-in Functions — Python 3.11.7 documentation) and the original issue.