Skip to content

Commit ab1cccb

Browse files
Use Field(default_factory=list) for CU response collections
Replace Optional[...] = None and mutable [] defaults on Page.spans, Page.words, DocumentContent.paragraphs, and ResultData.warnings with Field(default_factory=list). Removes a possible TypeError when the confidence evaluator iterates page.words and aligns with the repo's Pydantic convention. Tests updated to assert empty-list defaults. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0f069ac commit ab1cccb

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/ContentProcessor/src/libs/azure_helper/model/content_understanding.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from typing import List, Optional
1111

12-
from pydantic import BaseModel, ValidationInfo, field_validator
12+
from pydantic import BaseModel, Field, ValidationInfo, field_validator
1313

1414

1515
class Span(BaseModel):
@@ -103,8 +103,8 @@ class Page(BaseModel):
103103
angle: Optional[float] = None
104104
width: float
105105
height: float
106-
spans: Optional[List[Span]] = None
107-
words: Optional[List[Word]] = None
106+
spans: List[Span] = Field(default_factory=list)
107+
words: List[Word] = Field(default_factory=list)
108108
lines: Optional[List[Line]] = []
109109
paragraphs: Optional[List[Paragraph]] = []
110110

@@ -116,7 +116,7 @@ class DocumentContent(BaseModel):
116116
endPageNumber: int
117117
unit: str
118118
pages: List[Page]
119-
paragraphs: Optional[List[Paragraph]] = None
119+
paragraphs: List[Paragraph] = Field(default_factory=list)
120120

121121

122122
class Warning(BaseModel):
@@ -139,7 +139,7 @@ class ResultData(BaseModel):
139139
analyzerId: str
140140
apiVersion: str
141141
createdAt: str
142-
warnings: List[Warning] = []
142+
warnings: List[Warning] = Field(default_factory=list)
143143
contents: List[DocumentContent]
144144

145145

src/ContentProcessor/tests/unit/azure_helper/test_content_understanding_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_page_can_be_constructed_without_angle_spans_words(self):
216216
)
217217
assert page.pageNumber == 1
218218
assert page.angle is None
219-
assert page.spans is None
220-
assert page.words is None
219+
assert page.spans == []
220+
assert page.words == []
221221
assert page.lines == []
222222
assert page.paragraphs == []

src/tests/ContentProcessor/azure_helper/test_content_understanding_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_page_can_be_constructed_without_angle_spans_words(self):
216216
)
217217
assert page.pageNumber == 1
218218
assert page.angle is None
219-
assert page.spans is None
220-
assert page.words is None
219+
assert page.spans == []
220+
assert page.words == []
221221
assert page.lines == []
222222
assert page.paragraphs == []

0 commit comments

Comments
 (0)