[Python-ideas] namedtuple literals [Was: RE a new namedtuple]

Lucas Wiman lucas.wiman at gmail.com
Thu Jul 20 14:05:02 EDT 2017

On Thu, Jul 20, 2017 at 5:19 AM, Victor Stinner <victor.stinner at gmail.com>

> For me, namedtuple was first used to upgrade an old API from returning a
> tuple to a "named" tuple. There was a hard requirement on backward
> compatibility: namedtuple API is a superset of the tuple API.
> For new code, there is no such backward compatibility issue. If you don't
> need a type, types.Namespace is a good choice.
> Using ns=types.Namespace, you can replace (x=0, y=1) with ns(x=0, y=1). It
> already works, no syntax change.
> *If* someone really wants (x=0, y=1) syntax sugar, I would prefer to get a
> namespace (no indexed (tuple) API).

It's a minor point, but the main reason I use namedtuple is because it's
far easier to get a hashable object than writing one yourself. Namespaces
are not hashable. If the (x=0, y=1) sugar is accepted, IMO it should
immutable and hashable like tuples/namedtuples.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170720/d1f1a21e/attachment.html>

More information about the Python-ideas mailing list