Skip to content

[aw][code health] Minor guideline-compliance cleanup: stale docstring and banned hasattr/getattr in tests #894

@microsasa

Description

@microsasa

Summary

Three small guideline compliance issues, none worth a standalone issue, together form a meaningful cleanup pass.


1. Stale module-level docstring in cli.py

File: src/copilot_usage/cli.py, lines 1–4

Current:

"""CLI entry-point for copilot-usage.

Provides ``summary``, ``session``, ``cost``, and ``live`` commands,
plus an interactive Rich-based session when invoked without a subcommand.
"""

Problem: The vscode command (line ~653) was added later and was never mentioned in the module docstring. The docstring now misdescribes the module.

Fix: Add , vscode``` to the list of commands in the docstring.


2. getattr/hasattr in tests/test_packaging.py violates the "No getattr/hasattr" guideline

File: tests/test_packaging.py, lines 27–30

Current:

dunder_all: list[str] | None = getattr(mod, "__all__", None)  # noqa: B009
...
assert hasattr(mod, name), (  # noqa: B009

Problem: .github/CODING_GUIDELINES.md prohibits getattr/hasattr. The # noqa: B009 comments suppress ruff's constant-attribute getattr warning but do not address the guideline.

Fix:

  • Replace getattr(mod, "__all__", None) with mod.__dict__.get("__all__") (avoids getattr; uses the module's raw __dict__ which is always a plain dict).
  • Replace hasattr(mod, name) with name in dir(mod) or catch AttributeError on direct access.

3. hasattr in tests/copilot_usage/test_models.py violates the same guideline

File: tests/copilot_usage/test_models.py, line 269

Current:

assert not hasattr(d, "sessionStartTime")

Problem: Uses banned hasattr. The intent is to verify that a removed Pydantic field is not stored on the model instance.

Fix: Replace with assert "sessionStartTime" not in d.__dict__ — for Pydantic v2 models without extra="allow", the instance __dict__ contains exactly the declared fields, so this is equivalent and avoids hasattr.


Testing requirement

All three fixes are mechanical one-liners with no behaviour change. Run make check to verify after applying. No new tests required; the existing tests are the regression check.

Generated by Code Health Analysis · ● 10.5M ·

Metadata

Metadata

Assignees

No one assigned

    Labels

    awCreated by agentic workflowaw-dispatchedIssue has been dispatched to implementercode-healthCode cleanup and maintenance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions