Conversation
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>
There was a problem hiding this comment.
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 usesession.start_time is Noneinstead ofif not session.start_time. - Update header rendering to use
summary.start_time is not Nonein the formatted start-time expression. - Update session detail
session_startselection logic to use explicitis not Nonechecks forsummary.start_timeandevents[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. |
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #862
Summary
Four locations across
report.pyandrender_detail.pycheckeddatetime | Nonefields using Python truthiness (if x/if not x) instead of explicitis None/is not Noneguards. This PR replaces them for consistency, better pyright type narrowing, and latent correctness safety.Changes
report.pyif not session.start_time:if session.start_time is None:render_detail.py… if summary.start_time else "—"… if summary.start_time is not None else "—"render_detail.pyif summary.start_timeif summary.start_time is not Nonerender_detail.pyif events and events[0].timestampif events and events[0].timestamp is not NoneVerification
test_wheel_excludes_docsfailure is pre-existing and unrelated —uvnot in PATH).pyright --strictpasses with 0 errors.rufflint and format pass cleanly.