This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: introduction of default values for collection.namedtuple
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: acue, eric.smith, rhettinger, xtreak
Priority: normal Keywords:

Created on 2019-12-08 13:32 by acue, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
namedtupled-uml-patches.jpg acue, 2019-12-08 13:32
Messages (5)
msg358002 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2019-12-08 13:32
Hello,
I had the requirement to make excessive use of named tuples in an extended way. The applications are variable data sets with optional items. Typical in protocol dat a units, or e.g. mixed abstract filesystem types for heterogeneous file system types including URL and UNC.

As I saw the required changes are a couple of lines which I see as harmless. The implementation is available for Python2.7 and Python3.5+ in the project namedtupledefs, which is the patched code extracted from the *collections*.

The detailed descriptions for both versions are available at:
Python3: https://namedtupledefs3.sourceforge.io/
Python3: https://namedtupledefs.sourceforge.io/
Python2: https://namedtupledefs2.sourceforge.io/

Checked in PyPi + Sourceforge + github - the links are in the documents.

https://github.com/ArnoCan/namedtupledefs3/
https://github.com/ArnoCan/namedtupledefs2/
https://github.com/ArnoCan/namedtupledefs/

https://pypi.org/project/namedtupledefs[23]/

My proposal is to introduce the changes. It would be great for Python2.7 too, before the EOL.

WKR

WKR
msg358003 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-12-08 14:52
Is there something that your module can do that typing.NamedTuple can't do?

This won't be added to 2.7: 3.9 would be the first possible version to add a feature to.
msg358005 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-12-08 15:25
Is it different from the defaults parameter added in 3.7 with https://github.com/python/cpython/commit/3948207c610e931831828d33aaef258185df31db . The linked pypi package seems to do the same thing.
msg358014 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-12-08 18:07
Here's the status of the various ways to do it:

1) In 3.7, collections.namedtuple() added the *defaults* parameter and the *_field_defaults* attribute.

2) In 3.6.1, typing.NamedTuple added support for default values.

3) In older versions of Python, it was always possible to directly attach default values:

    >>> from collections import namedtuple
    >>> Point = namedtuple('Point', ('x', 'y'))
    >>> Point.__new__.__defaults__ = (10, )
    >>> Point(5)
    Point(x=5, y=10)

Given that we can't introduce new features to old versions of Python, it looks like this can be closed as "out-of-date".
msg358015 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-12-08 18:13
Agreed on closing this issue.
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83177
2019-12-08 19:35:12pablogsalsetstatus: open -> closed
resolution: out of date
stage: resolved
2019-12-08 18:13:03eric.smithsetmessages: + msg358015
2019-12-08 18:07:51rhettingersetmessages: + msg358014
2019-12-08 15:25:33xtreaksetnosy: + xtreak
messages: + msg358005
2019-12-08 14:52:12eric.smithsetversions: - Python 2.7, Python 3.8
nosy: + rhettinger, eric.smith

messages: + msg358003

assignee: rhettinger
2019-12-08 13:32:11acuecreate