Skip to content

The documentation of the "comments" API does not use the correct attributes #1551

@Vincent-Stragier

Description

@Vincent-Stragier

Hi,

I noticed that in the documentation, the comment object should have multiples attributes, including id, date, text, etc.

Adding a Comment
----------------
A simple example is adding a comment to a paragraph::
>>> from docx import Document
>>> document = Document()
>>> paragraph = document.add_paragraph("Hello, world!")
>>> comment = document.add_comment(
... runs=paragraph.runs,
... text="I have this to say about that"
... author="Steve Canny",
... initials="SC",
... )
>>> comment
<docx.comments.Comment object at 0x02468ACE>
>>> comment.id
0
>>> comment.author
'Steve Canny'
>>> comment.initials
'SC'
>>> comment.date
datetime.datetime(2025, 6, 11, 20, 42, 30, 0, tzinfo=datetime.timezone.utc)
>>> comment.text
'I have this to say about that'

On my laptop, I ran the following:

>>> from docx import Document
>>> document = Document()
>>> p = document.add_paragraph("Hello, world!")
>>> comment = document.add_comment(runs = p.runs, text="I have this to say about that", author="Steve Canny", initials="SC",)
>>> comment
<docx.comments.Comment object at 0x10b503230>
>>> comment.id
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Comment' object has no attribute 'id'
>>> comment.author
'Steve Canny'
>>> comment.initials
'SC'
>>> comment.text
'I have this to say about that'
>>> comment.timestamp
datetime.datetime(2026, 5, 5, 12, 5, 44, tzinfo=datetime.timezone.utc)
>>> document.comments
<docx.comments.Comments object at 0x10b555130>
>>> len(document.comments)
1
>>> c =  document.comments.get(0)
>>> c
<docx.comments.Comment object at 0x10b536ed0>
>>> [(o, type(getattr(c, o))) for o in dir(c) if not o.startswith("_")]
[('add_paragraph', <class 'method'>), ('add_table', <class 'method'>), ('author', <class 'str'>), ('comment_id', <class 'int'>), ('initials', <class 'str'>), ('iter_inner_content', <class 'method'>), ('paragraphs', <class 'list'>), ('part', <class 'docx.parts.comments.CommentsPart'>), ('tables', <class 'list'>), ('text', <class 'str'>), ('timestamp', <class 'datetime.datetime'>)]

The available attributes are:

  • author
  • comment_id
  • intitials
  • paragraphs
  • part
  • tables
  • text

@scanny, would you like a PR to fix the doc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions