mirror of
https://github.com/python/cpython.git
synced 2025-11-20 02:50:14 +00:00
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.
This commit is contained in:
parent
5c117dd227
commit
052b2dfdc9
4 changed files with 75 additions and 37 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue