[Python-ideas] Docstrings for namedtuple

Antoine Pitrou solipsis at pitrou.net
Sun Dec 16 15:52:07 CET 2012


On Sun, 16 Dec 2012 05:22:44 -0800
Eli Bendersky <eliben at gmail.com> wrote:
> On Wed, Dec 12, 2012 at 9:40 AM, Serhiy Storchaka <storchaka at gmail.com>wrote:
> 
> > What interface is better for specifying namedtuple field docstrings?
> >
> >     Point = namedtuple('Point', 'x y',
> >                        doc='Point: 2-dimensional coordinate',
> >                        field_docs=['abscissa', 'ordinate'])
> >
> > or
> >
> >     Point = namedtuple('Point', [('x', 'absciss'), ('y', 'ordinate')],
> >                        doc='Point: 2-dimensional coordinate')
> >
> > ?
> >
> >
> This may be a good time to say that personally I always disliked
> namedtuple's creation syntax. It is unpleasant in two respects:
> 
> 1. You have to repeat the name
> 2. You have to specify the fields in a space-separated string
> 
> I wish there was an alternative of something like:
> 
> @namedtuple
> class Point:
>   x = 0
>   y = 0

+1, this would be very nice. It would also allow default values as
shown above, which is a useful feature.

Regards

Antoine.





More information about the Python-ideas mailing list