New submission from R. David Murray:
Consider this code snippet, simplified from a real application:
def display(self, *columns)
getter = attrgetter(*columns)
toprint = [[str(x) for x in getter(row)] for row in self._rows]
This works great...as long as there are two or more columns to print.
If there is only one column, it bombs because the getter returns a value
instead of a tuple.
This would not be a problem in and of itself, but there is no way to
tell attrgetter that I want a tuple even if there is only one value.
I believe it would be backward compatible to allow:
to return a tuple, since a list cannot be an attribute name. The same
would apply to itemgetter, since a list cannot be a dictionary key.
components: Library (Lib)
stage: needs patch
title: Allow operator 'getter' methods to take a list and return a tuple
versions: Python 3.4
Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list