mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
bpo-43102: Set namedtuple __new__'s internal builtins to a dict. (GH-24439) (GH-24452)
This commit is contained in:
parent
48d16b4b0f
commit
29584aa6ac
3 changed files with 8 additions and 1 deletions
|
|
@ -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}))'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue