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.

Author poornaprudhvi
Recipients poornaprudhvi, terry.reedy
Date 2018-02-27.08:55:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519721710.54.0.467229070634.issue32961@psf.upfronthosting.co.za>
In-reply-to
Content
>>> from collections import namedtuple
>>> sample = namedtuple('Name','a','b','c')

This is returning the following code as output:

class Name(tuple):
    'Name(a,)'

    __slots__ = ()

    _fields = ('a',)

    def __new__(_cls, a,):
        'Create new instance of Name(a,)'
        return _tuple.__new__(_cls, (a,))

    @classmethod
    def _make(cls, iterable, new=tuple.__new__, len=len):
        'Make a new Name object from a sequence or iterable'
        result = new(cls, iterable)
        if len(result) != 1:
            raise TypeError('Expected 1 arguments, got %d' % len(result))
        return result

    def __repr__(self):
        'Return a nicely formatted representation string'
        return 'Name(a=%r)' % self

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values'
        return OrderedDict(zip(self._fields, self))

    def _replace(_self, **kwds):
        'Return a new Name object replacing specified fields with new values'
        result = _self._make(map(kwds.pop, ('a',), _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % kwds.keys())
        return result

    def __getnewargs__(self):
        'Return self as a plain tuple.  Used by copy and pickle.'
        return tuple(self)

    __dict__ = _property(_asdict)

    def __getstate__(self):
        'Exclude the OrderedDict from pickling'
        pass

    a = _property(_itemgetter(0), doc='Alias for field number 0')
History
Date User Action Args
2018-02-27 08:55:10poornaprudhvisetrecipients: + poornaprudhvi, terry.reedy
2018-02-27 08:55:10poornaprudhvisetmessageid: <1519721710.54.0.467229070634.issue32961@psf.upfronthosting.co.za>
2018-02-27 08:55:10poornaprudhvilinkissue32961 messages
2018-02-27 08:55:09poornaprudhvicreate