Root Cause
Two Pydantic Field declarations in models.py use default_factory=list for complex generic list types and suppress the resulting pyright warning with # pyright: ignore[reportUnknownVariableType]:
# models.py — AssistantMessageData
toolRequests: list[ToolRequest] = Field(default_factory=list) # pyright: ignore[reportUnknownVariableType]
# models.py — SessionSummary
shutdown_cycles: list[tuple[datetime | None, SessionShutdownData]] = Field( # pyright: ignore[reportUnknownVariableType]
default_factory=list
)
The coding guidelines already address this for dataclasses.field:
In dataclasses.field, use default_factory=lambda: [] (not default_factory=list) for mutable defaults — this avoids a known pyright false-positive.
The same fix applies to Pydantic Field when the element type is a complex generic (e.g. list[ToolRequest] or list[tuple[...]]). Pyright can infer the correct type from the field annotation when lambda: [] is used, but cannot do so reliably when the bare list builtin is passed. Simple list[str] fields work fine with default_factory=list; it is only complex generics that require the lambda.
The coding guidelines note "In Pydantic Field, default_factory=list is fine" — this is accurate for simple element types but incomplete for complex generics. The rule should be extended (or the code fixed) to cover this case.
Fix
Replace default_factory=list with default_factory=lambda: [] for both fields:
# AssistantMessageData
toolRequests: list[ToolRequest] = Field(default_factory=lambda: [])
# SessionSummary
shutdown_cycles: list[tuple[datetime | None, SessionShutdownData]] = Field(
default_factory=lambda: []
)
This removes both # pyright: ignore suppressions, keeps pyright in strict mode without exceptions, and is consistent with the dataclasses convention already mandated by the coding guidelines.
Update the "In Pydantic Field, default_factory=list is fine" line in CODING_GUIDELINES.md to note that complex generic list types require lambda: [].
Testing Requirement
- All existing model tests must pass without modification — the behaviour is identical; only the default factory closure changes.
- Verify that
pyright no longer reports reportUnknownVariableType on these fields (i.e. run make check cleanly after the change, with the # pyright: ignore comments removed).
Generated by Code Health Analysis · ● 2.4M · ◷
Root Cause
Two Pydantic
Fielddeclarations inmodels.pyusedefault_factory=listfor complex generic list types and suppress the resulting pyright warning with# pyright: ignore[reportUnknownVariableType]:The coding guidelines already address this for
dataclasses.field:The same fix applies to Pydantic
Fieldwhen the element type is a complex generic (e.g.list[ToolRequest]orlist[tuple[...]]). Pyright can infer the correct type from the field annotation whenlambda: []is used, but cannot do so reliably when the barelistbuiltin is passed. Simplelist[str]fields work fine withdefault_factory=list; it is only complex generics that require the lambda.The coding guidelines note "In Pydantic
Field,default_factory=listis fine" — this is accurate for simple element types but incomplete for complex generics. The rule should be extended (or the code fixed) to cover this case.Fix
Replace
default_factory=listwithdefault_factory=lambda: []for both fields:This removes both
# pyright: ignoresuppressions, keeps pyright in strict mode without exceptions, and is consistent with the dataclasses convention already mandated by the coding guidelines.Update the "In Pydantic
Field,default_factory=listis fine" line inCODING_GUIDELINES.mdto note that complex generic list types requirelambda: [].Testing Requirement
pyrightno longer reportsreportUnknownVariableTypeon these fields (i.e. runmake checkcleanly after the change, with the# pyright: ignorecomments removed).