aboutsummaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2021-02-04 15:52:16 -0800
committerGitHub <noreply@github.com>2021-02-04 15:52:16 -0800
commitb6d68aa08baebb753534a26d537ac3c0d2c21c79 (patch)
tree8678fd8056357e83a28a44dda92f857a01aa8ec9 /Lib
parentbpo-42882: Fix MSVC warnings in pystate.c (GH-24440) (diff)
downloadcpython-b6d68aa08baebb753534a26d537ac3c0d2c21c79.tar.gz
cpython-b6d68aa08baebb753534a26d537ac3c0d2c21c79.tar.bz2
cpython-b6d68aa08baebb753534a26d537ac3c0d2c21c79.zip
bpo-43102: Set namedtuple __new__'s internal builtins to a dict. (GH-24439)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/collections/__init__.py2
-rw-r--r--Lib/test/test_collections.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 7d338131d67..6fe3c4c5aa5 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -407,7 +407,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}))'
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index a1ca958257a..befb7ab436c 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -681,6 +681,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