[Python-ideas] Anonymous namedtuples

Chris Angelico rosuav at gmail.com
Tue Apr 19 06:46:02 EDT 2016

On Tue, Apr 19, 2016 at 8:25 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 19 April 2016 at 11:06, Chris Angelico <rosuav at gmail.com> wrote:
>> That said, though: I don't often feel the yearning for quick
>> namedtuples. A function that today returns a namedtuple of 'x' and 'y'
>> can't in the future grow a 'z' without breaking any callers that
>> unpack "x, y = func()", so extensible return objects have to forego
>> unpacking (eg using a dict or SimpleNamespace).
> Possibly the docs for namedtuple should refer the user to
> SimpleNamespace as an alternative if "being a tuple subclass" isn't an
> important requirement. Or possibly SimpleNamespace should be in the
> collections module (alongside namedtuple) rather than in the types
> module?
> The issue may simply be that SimpleNamespace isn't as discoverable as
> it should be?

That's entirely possible. For the situations where order is
insignificant and unpacking is unnecessary, a SimpleNamespace would be
perfect, if people knew about it. Probably not worth moving the actual
class, but a quick little docs link might help.


More information about the Python-ideas mailing list