From 987c87074d844c44492822d22224558c4da1a7a9 Mon Sep 17 00:00:00 2001 From: kumburovicbranko682-boop Date: Sun, 28 Jun 2026 08:32:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20singleresult=20dataclass=20fields?= =?UTF-8?q?=20default=20to=20none=20but=20typed=20as=20non-optional=20?= =?UTF-8?q?=E2=80=94=20will=20crash=20on=20attribute=20access?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `SingleResult` dataclass declares `example: Example` and `result: RunResult` but defaults both to `None`. The `# type: ignore[assignment]` silences the type checker but does not fix the runtime problem: any code that constructs `SingleResult()` without explicitly setting both fields and then accesses `sr.example.name` or `sr.result.exit_code` will crash with `AttributeError: 'NoneType' object has no attribute 'name'`. The sibling class `RunResult` demonstrates the correct pattern — every field has a concrete default. `Example` requires three non-defaulted args (name, path, cwd), so the author punted with `None`. Callers have no type-level signal that these fields can be absent. Affected files: models.py Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com> --- sdk/python/validation/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/python/validation/models.py b/sdk/python/validation/models.py index cbc231342..dad60ea68 100644 --- a/sdk/python/validation/models.py +++ b/sdk/python/validation/models.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from pathlib import Path +from typing import Optional @dataclass @@ -35,5 +36,5 @@ class RunResult: class SingleResult: """Result of running one example with one model (single-run mode).""" - example: Example = None # type: ignore[assignment] - result: RunResult = None # type: ignore[assignment] + example: Optional[Example] = None + result: Optional[RunResult] = None