]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43102: Set namedtuple __new__'s internal builtins to a dict. (GH-24439) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 5 Feb 2021 00:12:34 +0000 (16:12 -0800)
committerGitHub <noreply@github.com>
Fri, 5 Feb 2021 00:12:34 +0000 (16:12 -0800)
Lib/collections/__init__.py
Lib/test/test_collections.py
Misc/NEWS.d/next/Library/2021-02-03-22-55-27.bpo-43102.TSlZ6J.rst [new file with mode: 0644]

index bc69a6757f29483dad16ea47c7217925c70226a4..5bdd3b3516d3b2c6ddd206745a4ca02a9901def4 100644 (file)
@@ -424,7 +424,7 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
 
     namespace = {
         '_tuple_new': tuple_new,
-        '__builtins__': None,
+        '__builtins__': {},
         '__name__': f'namedtuple_{typename}',
     }
     code = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
index 057ec92015cf4f4ef72507bd75c53b52475cc9c2..3ff660cf7a37be31c19790a47f9311de7cab6827 100644 (file)
@@ -680,6 +680,11 @@ class TestNamedTuple(unittest.TestCase):
         self.assertEqual(np.x, 1)
         self.assertEqual(np.y, 2)
 
+    def test_new_builtins_issue_43102(self):
+        self.assertEqual(
+            namedtuple('C', ()).__new__.__globals__['__builtins__'],
+            {})
+
 
 ################################################################################
 ### Abstract Base Classes
diff --git a/Misc/NEWS.d/next/Library/2021-02-03-22-55-27.bpo-43102.TSlZ6J.rst b/Misc/NEWS.d/next/Library/2021-02-03-22-55-27.bpo-43102.TSlZ6J.rst
new file mode 100644 (file)
index 0000000..985fd68
--- /dev/null
@@ -0,0 +1,2 @@
+The namedtuple __new__ method had its __builtins__ set to None instead
+of an actual dictionary.  This created problems for introspection tools.