summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-08 20:25:48 (GMT)
committerGitHub <noreply@github.com>2020-06-08 20:25:48 (GMT)
commit299d3d1c52ffc7f9e200de577fe5d1d5310d7c27 (patch)
tree8100310435118818a88d6b9e11a0937fc7f4aaf8
parentb155381314c632e7dd452fbade3903e58657cfc7 (diff)
downloadcpython-299d3d1c52ffc7f9e200de577fe5d1d5310d7c27.zip
cpython-299d3d1c52ffc7f9e200de577fe5d1d5310d7c27.tar.gz
cpython-299d3d1c52ffc7f9e200de577fe5d1d5310d7c27.tar.bz2
Minor improvement to the namedtuple implementation (GH-20741) (GH-20742)
-rw-r--r--Lib/collections/__init__.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index d11d120..61199ab 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -399,7 +399,9 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
# Variables used in the methods and docstrings
field_names = tuple(map(_sys.intern, field_names))
num_fields = len(field_names)
- arg_list = repr(field_names).replace("'", "")[1:-1]
+ arg_list = ', '.join(field_names)
+ if num_fields == 1:
+ arg_list += ','
repr_fmt = '(' + ', '.join(f'{name}=%r' for name in field_names) + ')'
tuple_new = tuple.__new__
_dict, _tuple, _len, _map, _zip = dict, tuple, len, map, zip
@@ -410,6 +412,7 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
namespace = {'_tuple_new': tuple_new, '__builtins__': None,
'__name__': f'namedtuple_{typename}'}
__new__ = eval(s, namespace)
+ __new__.__name__ = '__new__'
__new__.__doc__ = f'Create new instance of {typename}({arg_list})'
if defaults is not None:
__new__.__defaults__ = defaults