[Python-ideas] A subclassing API for named tuples?
Nick Coghlan
ncoghlan at gmail.com
Fri Feb 15 09:25:53 CET 2013
On Fri, Feb 15, 2013 at 5:07 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Thu, 14 Feb 2013 18:11:38 -0800
> Larry Hastings <larry at hastings.org> wrote:
>> On 02/14/2013 05:19 AM, Nick Coghlan wrote:
>> > A recurring suggestion for collections.namedtuple is that it would be
>> > nice to be able to define them like this [...]
>>
>> FWIW, I think namedtuple is overused. Not that there's anything
>> innately wrong with namedtuple; it's just that I think too many types
>> are iterable which shouldn't be. (Nobody unpacks the stat_result
>> anymore, that's like 1995 man.) I suggest people use
>> types.SimpleNamespace unless iterability is specifically required.
>
> There are tons of cases where tuple unpacking is a very convenient API.
Indeed. In particular, consuming namespaces from an iterator is
substantially more annoying than consuming a tuple.
I'd put the size cutoff for switching over to a namespace somewhere
around the 5 item mark. At 2-3, the tuple is often clearly superior,
at 4 it's arguable, at 5, unpacking starts to get a bit hard to read.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list