Message299535
Here is the diff. Note that I assume implementation of #31085, which allows me to push determination of a name for the namedtuple down into namedtuple itself:
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 62cf708..d507d23 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -14,7 +14,8 @@ list, set, and tuple.
'''
-__all__ = ['deque', 'defaultdict', 'namedtuple', 'UserDict', 'UserList',
+__all__ = ['deque', 'defaultdict', 'namedtuple', 'namedattrgetter',
+ 'UserDict', 'UserList',
'UserString', 'Counter', 'OrderedDict', 'ChainMap']
# For backwards compatibility, continue to make the collections ABCs
@@ -23,7 +24,7 @@ from _collections_abc import *
import _collections_abc
__all__ += _collections_abc.__all__
-from operator import itemgetter as _itemgetter, eq as _eq
+from operator import itemgetter as _itemgetter, attrgetter as _attrgetter, eq as _eq
from keyword import iskeyword as _iskeyword
import sys as _sys
import heapq as _heapq
@@ -451,6 +452,14 @@ def namedtuple(typename, field_names, *, verbose=False, rename=False, module=Non
return result
+def namedattrgetter (attr, *attrs):
+ ag = _attrgetter (attr, *attrs)
+
+ if attrs:
+ nt = namedtuple (None, (attr,) + attrs, rename=True)
+ return lambda obj: nt._make (ag (obj))
+ else:
+ return ag
########################################################################
### Counter |
|
Date |
User |
Action |
Args |
2017-07-31 01:21:23 | Isaac Morland | set | recipients:
+ Isaac Morland |
2017-07-31 01:21:23 | Isaac Morland | set | messageid: <1501464083.62.0.710684821005.issue31086@psf.upfronthosting.co.za> |
2017-07-31 01:21:23 | Isaac Morland | link | issue31086 messages |
2017-07-31 01:21:23 | Isaac Morland | create | |
|