[issue31085] Add option for namedtuple to name its result type automatically

Raymond Hettinger report at bugs.python.org
Wed Aug 2 01:12:44 EDT 2017


Raymond Hettinger added the comment:

[R David Murray]
> So I vote -0.5.

Put me down for a full -1:

* This would be a potentially  confusing addition to the API.

* It may also encourage bad practices that we don't want to see in real code. 

* We want to be able to search for the namedtuple definition, want to have a meaningful repr, and want pickling to be easy.

* This doesn't have to be shoe-horned into the namedtuple API.  If an actual need did arise, it is trivial to write a wrapper that specifies whatever auto-naming logic happens to make sense for a particular application:

    >>> from collections import namedtuple
    >>> def auto_namedtuple(*attrnames, **kwargs):
            typename = '_'.join(attrnames)
            return namedtuple(typename, attrnames, **kwargs)

    >>> NT = auto_namedtuple('name', 'rank', 'serial')
    >>> print(NT.__doc__)
    name_rank_serial(name, rank, serial)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31085>
_______________________________________


More information about the Python-bugs-list mailing list