[Python-ideas] Anonymous namedtuples
p.f.moore at gmail.com
Tue Apr 19 10:39:48 EDT 2016
On 19 April 2016 at 15:26, Random832 <random832 at fastmail.com> wrote:
> On Tue, Apr 19, 2016, at 06:25, Paul Moore wrote:
>> Possibly the docs for namedtuple should refer the user to
>> SimpleNamespace as an alternative if "being a tuple subclass" isn't an
>> important requirement.
> Just my two cents - for the use cases that I would find this useful for
> (I usually end up just using tuple), a hashable "FrozenSimpleNamespace"
> would be nice. Or even one that has immutable key fields that are used
> as the basis for the hash but that you can hang other values off of
Having done some digging just now... SimpleNamespace is basically just
exposing for end users, the type that is used to build the
sys.implementation object. The definition is *literally* nothing more
SimpleNamespace = type(sys.implementation)
Variations such as you suggest may indeed be useful, but the existing
implementation was essentially a free benefit of "we use this one
ourselves in the core". Going beyond that, any additional types
probably need to justify themselves a bit better - and at that point
the usual "publish on PyPI as a standalone module and see how useful
they turn out to be" suggestion probably applies.
More information about the Python-ideas