Skip to content

Support default values for collections.namedtuple? #4788

Closed

Description

@ilevkivskyi

Python 3.7 adds support for specifying default values in call to collections.namedtuple, see python/cpython#4859. So for example this is valid:

from collections import namedtuple

NT = namedtuple('NT', ('x', 'y'), defaults=(0, 0))
NT()
NT(1)
NT(1, 2)

Should we support this, or supporting default values for typing.NamedTuple (already implemented) is enough?

Activity

  1. gvanrossum commented on Mar 25, 2018

    @gvanrossum
    Member

    The short form of collections.namedtuple is very popular (ask @rhettinger) and I think we should make it as easy as possible to translate its use to typing.NamedTuple. So I think we should support it.

  2. JukkaL commented on Mar 26, 2018

    @JukkaL
    Collaborator

    I agree with @gvanrossum. Also, this doesn't look like a lot of work to implement. Tagging as high priority since 3.7 release date is pretty close.

  3. JelleZijlstra commented on Aug 3, 2018

    @JelleZijlstra
    Member

    Fixed by #5215.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions