Skip to content

fix(parser): remove isinstance checks and relocate __all__ (#988)#991

Merged
microsasa merged 1 commit intomainfrom
fix/isinstance-and-all-position-988-ec5ffe2c94a79288
Apr 18, 2026
Merged

fix(parser): remove isinstance checks and relocate __all__ (#988)#991
microsasa merged 1 commit intomainfrom
fix/isinstance-and-all-position-988-ec5ffe2c94a79288

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #988

Changes

Finding 1 — Remove isinstance in non-boundary business logic

  • _insert_events_entry: Changed parameter type from list[SessionEvent] | tuple[SessionEvent, ...] to Sequence[SessionEvent] and now calls tuple(events) unconditionally, eliminating the isinstance guard.
  • get_all_sessions: Unified the incremental-vs-full-parse branches to always produce list[SessionEvent] (list(ev_cached.events) + new_events), removing the need for isinstance before passing to _build_session_summary_with_meta.

Finding 2 — Relocate __all__ after all imports

Moved 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 check passes cleanly: ruff lint, ruff format, pyright strict (0 errors), bandit, unit tests (99% coverage), and e2e tests (86 passed).
  • No new type: ignore suppressions added.

Generated by Issue Implementer · ● 4.9M ·

- 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>
Copilot AI review requested due to automatic review settings April 18, 2026 21:04
@microsasa microsasa added the aw Created by agentic workflow label Apr 18, 2026
@microsasa microsasa enabled auto-merge April 18, 2026 21:04
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 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 isinstance checks (unifies to list[SessionEvent] in get_all_sessions and accepts Sequence[SessionEvent] in _insert_events_entry).
  • Relocates __all__ to after all imports to match package conventions.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 18, 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.

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.

@microsasa microsasa merged commit b9f30bc into main Apr 18, 2026
8 checks passed
@microsasa microsasa deleted the fix/isinstance-and-all-position-988-ec5ffe2c94a79288 branch April 18, 2026 21:09
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] isinstance in non-boundary business logic and __all__ placed mid-import-block in parser.py

2 participants