classification
Title: namedtuple documentation
Type: Stage: resolved
Components: Documentation Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Laur Joost, docs@python, python-dev, zach.ware
Priority: normal Keywords:

Created on 2015-11-23 00:44 by Laur Joost, last changed 2015-11-24 06:19 by python-dev. This issue is now closed.

Messages (4)
msg255121 - (view) Author: Laur Joost (Laur Joost) Date: 2015-11-23 00:44
collections.namedtuple documentation has an example about changing the resulting class docstrings:

  Docstrings can be customized by making direct assignments to the
  ``__doc__`` fields:
  
     >>> Book = namedtuple('Book', ['id', 'title', 'authors'])
     >>> Book.__doc__ += ': Hardcover book in active collection'

This seems to work for the resulting class, but not the field names:

    MsgPacket = namedtuple('MsgPacket', ['sender', 'target', 'sig', 'ser_msg'])
    MsgPacket.__doc__ = '. Message packet format. This is the data added to client queues.'
    MsgPacket.sender.__doc__ = 'Sender public key.'

gives

    Traceback (most recent call last):
      File "C:/UTCloud/UT/DS/S11/server.py", line 42, in <module>
        MsgPacket.sender.__doc__ = 'Sender public key.'
    AttributeError: readonly attribute
msg255122 - (view) Author: Laur Joost (Laur Joost) Date: 2015-11-23 00:51
Did my testing on 3.4.3 (other computer). My apologies.
msg255123 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2015-11-23 02:53
I wonder if it's worth a ..versionchanged note in the namedtuple docs pointing out that __doc__ assignment on fields only works in 3.5+ due to property docstrings becoming writable.
msg255249 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-24 06:19
New changeset f611e2244c69 by Raymond Hettinger in branch '3.5':
Issue #25700: Clarify that namedtuple property docstrings became writeable in 3.5
https://hg.python.org/cpython/rev/f611e2244c69
History
Date User Action Args
2015-11-24 06:19:23python-devsetnosy: + python-dev
messages: + msg255249
2015-11-23 02:53:59zach.waresetnosy: + zach.ware

messages: + msg255123
stage: resolved
2015-11-23 00:51:40Laur Joostsetstatus: open -> closed
resolution: not a bug
messages: + msg255122
2015-11-23 00:44:40Laur Joostcreate