summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-05-26 05:00:31 (GMT)
committerGitHub <noreply@github.com>2020-05-26 05:00:31 (GMT)
commita729f4abb8a3b13b63d46c450faf64202751449b (patch)
tree29e1becea242e860cd8ffd5c6f455ebf6f504d22 /Lib
parentfda47659bbc27097abb6e3b8a380bff13a753eb0 (diff)
downloadcpython-a729f4abb8a3b13b63d46c450faf64202751449b.zip
cpython-a729f4abb8a3b13b63d46c450faf64202751449b.tar.gz
cpython-a729f4abb8a3b13b63d46c450faf64202751449b.tar.bz2
Simplify creation of the __new__ method in namedtuple() (GH-20361) (GH-20409)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/collections/__init__.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index c4bff59..011a0c1 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -406,11 +406,9 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
# Create all the named tuple methods to be added to the class namespace
- s = f'def __new__(_cls, {arg_list}): return _tuple_new(_cls, ({arg_list}))'
+ s = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
namespace = {'_tuple_new': tuple_new, '__name__': f'namedtuple_{typename}'}
- # Note: exec() has the side-effect of interning the field names
- exec(s, namespace)
- __new__ = namespace['__new__']
+ __new__ = eval(s, namespace)
__new__.__doc__ = f'Create new instance of {typename}({arg_list})'
if defaults is not None:
__new__.__defaults__ = defaults