22
33from __future__ import annotations
44
5- from typing import TYPE_CHECKING
5+ from typing import TYPE_CHECKING , Iterator
66
77from docx .blkcntnr import BlockItemContainer
88
99if TYPE_CHECKING :
10- from docx .oxml .comments import CT_Comments
10+ from docx .oxml .comments import CT_Comment , CT_Comments
1111 from docx .parts .comments import CommentsPart
1212
1313
@@ -18,6 +18,13 @@ def __init__(self, comments_elm: CT_Comments, comments_part: CommentsPart):
1818 self ._comments_elm = comments_elm
1919 self ._comments_part = comments_part
2020
21+ def __iter__ (self ) -> Iterator [Comment ]:
22+ """Iterator over the comments in this collection."""
23+ return (
24+ Comment (comment_elm , self ._comments_part )
25+ for comment_elm in self ._comments_elm .comment_lst
26+ )
27+
2128 def __len__ (self ) -> int :
2229 """The number of comments in this collection."""
2330 return len (self ._comments_elm .comment_lst )
@@ -36,3 +43,7 @@ class Comment(BlockItemContainer):
3643 Note that certain content like tables may not be displayed in the Word comment sidebar due to
3744 space limitations. Such "over-sized" content can still be viewed in the review pane.
3845 """
46+
47+ def __init__ (self , comment_elm : CT_Comment , comments_part : CommentsPart ):
48+ super ().__init__ (comment_elm , comments_part )
49+ self ._comment_elm = comment_elm
0 commit comments