Skip to content

Quality: SingleResult dataclass fields default to None but typed as non-Optional — will crash on attribute access#288

Open
kumburovicbranko682-boop wants to merge 1 commit into
agentspan-ai:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/singleresult-dataclass-fields-default-to
Open

Quality: SingleResult dataclass fields default to None but typed as non-Optional — will crash on attribute access#288
kumburovicbranko682-boop wants to merge 1 commit into
agentspan-ai:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/singleresult-dataclass-fields-default-to

Conversation

@kumburovicbranko682-boop

Copy link
Copy Markdown

✨ Code Quality

Problem

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.

Severity: high
File: sdk/python/validation/models.py

Solution

from typing import Optional

@DataClass
class SingleResult:
"""Result of running one example with one model (single-run mode)."""

example: Optional[Example] = None
result: Optional[RunResult] = None

Then guard all consumers:

if single_result.example is not None:

...

Changes

  • sdk/python/validation/models.py (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced


🤖 About this PR

This pull request was generated by ContribAI, an AI agent
that helps improve open source projects. The change was:

  1. Discovered by automated code analysis
  2. Generated by AI with context-aware code generation
  3. Self-reviewed by AI quality checks

If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!

Closes #287

…non-optional — will crash on attribute access

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>
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.

fix: singleresult dataclass fields default to none but typed as non-optional — will crash on attribute access

1 participant