Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
| 277 | return self.__class__, self._attrs |
| 278 | |
| 279 | class itemgetter: |
| 280 | """ |
| 281 | Return a callable object that fetches the given item(s) from its operand. |
| 282 | After f = itemgetter(2), the call f(r) returns r[2]. |
| 283 | After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3]) |
| 284 | """ |
| 285 | __slots__ = ('_items', '_call') |
| 286 | |
| 287 | def __init__(self, item, /, *items): |
| 288 | if not items: |
| 289 | self._items = (item,) |
| 290 | def func(obj): |
| 291 | return obj[item] |
| 292 | self._call = func |
| 293 | else: |
| 294 | self._items = items = (item,) + items |
| 295 | def func(obj): |
| 296 | return tuple(obj[i] for i in items) |
| 297 | self._call = func |
| 298 | |
| 299 | def __call__(self, obj, /): |
| 300 | return self._call(obj) |
| 301 | |
| 302 | def __repr__(self): |
| 303 | return '%s.%s(%s)' % (self.__class__.__module__, |
| 304 | self.__class__.__name__, |
| 305 | ', '.join(map(repr, self._items))) |
| 306 | |
| 307 | def __reduce__(self): |
| 308 | return self.__class__, self._items |
| 309 | |
| 310 | class methodcaller: |
| 311 | """ |
no outgoing calls
searching dependent graphs…