Conversation
- Remove isinstance in _insert_events_entry by accepting Sequence[SessionEvent] and calling tuple() unconditionally. - Unify get_all_sessions event type to list[SessionEvent] so the isinstance guard before _build_session_summary_with_meta is no longer needed. - Move __all__ from mid-import-block to after all imports, matching the convention used by other modules in the package. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR performs a small parser cleanup in src/copilot_usage/parser.py, aligning internal APIs with the project’s typing guidelines and standardizing module organization.
Changes:
- Normalizes internal event collection types to avoid runtime
isinstancechecks (unifies tolist[SessionEvent]inget_all_sessionsand acceptsSequence[SessionEvent]in_insert_events_entry). - Relocates
__all__to after all imports to match package conventions.
Contributor
There was a problem hiding this comment.
Low-impact refactoring that removes isinstance checks from business logic per coding guidelines and relocates __all__ to follow the project's import convention. No behavioral changes — same data flows through the same paths. CI green, single file changed. 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 #988
Changes
Finding 1 — Remove
isinstancein non-boundary business logic_insert_events_entry: Changed parameter type fromlist[SessionEvent] | tuple[SessionEvent, ...]toSequence[SessionEvent]and now callstuple(events)unconditionally, eliminating theisinstanceguard.get_all_sessions: Unified the incremental-vs-full-parse branches to always producelist[SessionEvent](list(ev_cached.events) + new_events), removing the need forisinstancebefore passing to_build_session_summary_with_meta.Finding 2 — Relocate
__all__after all importsMoved the
__all__definition from between third-party and local imports to after the last local import block, matching the convention used by every other module in the package.Verification
make checkpasses cleanly: ruff lint, ruff format, pyright strict (0 errors), bandit, unit tests (99% coverage), and e2e tests (86 passed).type: ignoresuppressions added.