Skip to content

fix: replace datetime truthiness checks with explicit is None guards (#862)#867

Merged
microsasa merged 1 commit intomainfrom
fix/nullable-datetime-truthiness-guards-862-b481e646df8d4914
Apr 8, 2026
Merged

fix: replace datetime truthiness checks with explicit is None guards (#862)#867
microsasa merged 1 commit intomainfrom
fix/nullable-datetime-truthiness-guards-862-b481e646df8d4914

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #862

Summary

Four locations across report.py and render_detail.py checked datetime | None fields using Python truthiness (if x / if not x) instead of explicit is None / is not None guards. This PR replaces them for consistency, better pyright type narrowing, and latent correctness safety.

Changes

File Line Before After
report.py 158 if not session.start_time: if session.start_time is None:
render_detail.py 184 … if summary.start_time else "—" … if summary.start_time is not None else "—"
render_detail.py 384 if summary.start_time if summary.start_time is not None
render_detail.py 387 if events and events[0].timestamp if events and events[0].timestamp is not None

Verification

  • All 1239 unit tests pass (the single test_wheel_excludes_docs failure is pre-existing and unrelated — uv not in PATH).
  • pyright --strict passes with 0 errors.
  • ruff lint and format pass cleanly.

Generated by Issue Implementer · ● 2.8M ·

Replace four truthiness-based None checks on datetime fields with
explicit `is None` / `is not None` guards for consistency, type
narrowing, and correctness.

Closes #862

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Apr 8, 2026
@microsasa microsasa enabled auto-merge April 8, 2026 18:34
Copilot AI review requested due to automatic review settings April 8, 2026 18:34
@microsasa microsasa added the aw Created by agentic workflow label Apr 8, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves type-safety and consistency by replacing truthiness checks on datetime | None fields with explicit is None / is not None guards in the reporting/rendering layer, aligning better with strict Pyright narrowing.

Changes:

  • Update _format_session_running_time() to use session.start_time is None instead of if not session.start_time.
  • Update header rendering to use summary.start_time is not None in the formatted start-time expression.
  • Update session detail session_start selection logic to use explicit is not None checks for summary.start_time and events[0].timestamp.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/copilot_usage/report.py Uses an explicit None guard for SessionSummary.start_time to improve correctness and type narrowing.
src/copilot_usage/render_detail.py Replaces datetime truthiness checks with is not None in header rendering and session start-time derivation.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 8, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quality Gate: APPROVED

Low-impact correctness fix — replaces 4 Python truthiness checks (if x / if not x) with explicit is None / is not None guards on datetime | None fields in report.py and render_detail.py.

Evaluation:

  • Code quality: Good. Changes are minimal, consistent with coding guidelines (strict typing), and improve pyright type narrowing.
  • Tests: All 1239 unit tests pass; CI green across all 8 checks (lint, typecheck, CodeQL, etc.).
  • Impact: LOW — no behavioral change (datetime objects are always truthy), no API/model/logic modifications.

Auto-approving for merge.

@microsasa microsasa merged commit f59234d into main Apr 8, 2026
8 checks passed
@microsasa microsasa deleted the fix/nullable-datetime-truthiness-guards-862-b481e646df8d4914 branch April 8, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][code health] Nullable datetime fields checked with truthiness instead of is None / is not None

2 participants