bpo-42990: Add __builtins__ attribute to functions (GH-24559)

Expose the new PyFunctionObject.func_builtins member in Python as a
new __builtins__ attribute on functions.

Document also the behavior change in What's New in Python 3.10.
This commit is contained in:
Victor Stinner 2021-02-18 12:35:37 +01:00 committed by GitHub
parent 366dc3a135
commit a3c3ffa68e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 3 deletions

View file

@ -73,6 +73,11 @@ class FunctionPropertiesTest(FuncAttrsTest):
self.cannot_set_attr(self.b, '__globals__', 2,
(AttributeError, TypeError))
def test___builtins__(self):
self.assertIs(self.b.__builtins__, __builtins__)
self.cannot_set_attr(self.b, '__builtins__', 2,
(AttributeError, TypeError))
def test___closure__(self):
a = 12
def f(): print(a)