Skip to content

refactor(dataclass): remove pyright ignores by using parameterized generic aliases as field factories#5

Merged
shenxiangzhuang merged 3 commits intomasterfrom
copilot/optimize-code-and-design
Mar 10, 2026
Merged

refactor(dataclass): remove pyright ignores by using parameterized generic aliases as field factories#5
shenxiangzhuang merged 3 commits intomasterfrom
copilot/optimize-code-and-design

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

field(default_factory=list) causes Pyright strict mode to infer list[Unknown] regardless of the field's type annotation, requiring # pyright: ignore[reportUnknownVariableType] suppressions. Using the parameterized form list[T] / dict[K, V] as the factory gives Pyright the exact return type it needs.

Changes

  • 8 fields across 5 files — replaced bare list/dict factories with their parameterized equivalents and removed all associated ignore comments:
File Field Factory
kagent/state.py tools: list[Tool] list[Tool]
kagent/trace/entry.py data: dict[str, Any] dict[str, Any]
kcastle/providers/config.py options: dict[str, object] ×2 dict[str, object]
kcastle/providers/config.py models: list[ModelConfig] list[ModelConfig]
kcastle/config.py options: dict[str, object] dict[str, object]
kcastle/config.py providers: dict[str, ProviderEntry] dict[str, ProviderEntry]
kcastle/skills/skill.py tags: list[str] list[str]
# Before — Pyright infers list[Unknown], ignore needed
tools: list[Tool] = field(default_factory=list)  # pyright: ignore[reportUnknownVariableType]

# After — Pyright infers list[Tool] exactly, no ignore needed
tools: list[Tool] = field(default_factory=list[Tool])

The remaining # pyright: ignore[reportUnknownVariableType] comments in the codebase (on dict-iteration over untyped YAML data) are a separate, unrelated issue and are not touched here.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…eld factories

Co-authored-by: shenxiangzhuang <17157965+shenxiangzhuang@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor code and design framework for improvements refactor(kagent): replace unnecessary lambda wrappers in dataclass field factories Mar 10, 2026
…enerics, removing pyright ignores

Co-authored-by: shenxiangzhuang <17157965+shenxiangzhuang@users.noreply.github.com>
Copilot AI changed the title refactor(kagent): replace unnecessary lambda wrappers in dataclass field factories refactor(dataclass): remove pyright ignores by using parameterized generic aliases as field factories Mar 10, 2026
@shenxiangzhuang shenxiangzhuang marked this pull request as ready for review March 10, 2026 05:56
@shenxiangzhuang shenxiangzhuang merged commit fdac7db into master Mar 10, 2026
10 checks passed
@shenxiangzhuang shenxiangzhuang deleted the copilot/optimize-code-and-design branch March 10, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants