summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-12-31 12:15:16 (GMT)
committerGitHub <noreply@github.com>2018-12-31 12:15:16 (GMT)
commit052b2dfdc967a8c061ff9561534e905009b88b8c (patch)
tree1b9c6c026ff687e9332116d52d2d9ec55acf1abb /Lib/collections
parent5c117dd227e1b4c4f0a62564d8592f1ba45c91eb (diff)
downloadcpython-052b2dfdc967a8c061ff9561534e905009b88b8c.zip
cpython-052b2dfdc967a8c061ff9561534e905009b88b8c.tar.gz
cpython-052b2dfdc967a8c061ff9561534e905009b88b8c.tar.bz2
bpo-32492: Tweak _collections._tuplegetter. (GH-11367)
* Replace the docstrings cache with sys.intern(). * Improve tests. * Unify names of tp_descr_get and tp_descr_set functions.
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 0b74c3f..c31d7b7 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -316,8 +316,6 @@ try:
except ImportError:
_tuplegetter = lambda index, doc: property(_itemgetter(index), doc=doc)
-_nt_itemgetters = {}
-
def namedtuple(typename, field_names, *, rename=False, defaults=None, module=None):
"""Returns a new subclass of tuple with named fields.
@@ -456,16 +454,9 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
'_asdict': _asdict,
'__getnewargs__': __getnewargs__,
}
- cache = _nt_itemgetters
for index, name in enumerate(field_names):
- try:
- doc = cache[index]
- except KeyError:
- doc = f'Alias for field number {index}'
- cache[index] = doc
-
- tuplegetter_object = _tuplegetter(index, doc)
- class_namespace[name] = tuplegetter_object
+ doc = _sys.intern(f'Alias for field number {index}')
+ class_namespace[name] = _tuplegetter(index, doc)
result = type(typename, (tuple,), class_namespace)