Skip to content

Add types for debug utilities - #2072

Open
laclance wants to merge 2 commits into
lightly-ai:masterfrom
laclance:add-types-debug
Open

laclance wants to merge 2 commits into
lightly-ai:masterfrom
laclance:add-types-debug

Conversation

@laclance

@laclance laclance commented Sep 30, 2026 •

Copy link
Copy Markdown

Part of #1635.

Summary

  • add type annotations to lightly/utils/debug.py and tests/utils/test_debug.py
  • remove both files from the mypy exclusion list
  • improve optional matplotlib handling by keeping the pyplot module separate from import errors
  • remove an unused torchvision import
  • preserve the invalid-transform test with a targeted # type: ignore[arg-type]

Validation

  • make type-check
  • make format-check
  • uv run --frozen pytest tests/utils/test_debug.py — 11 passed

Add type annotations to lightly/utils/debug.py and tests/utils/test_debug.py. Remove both files from the mypy exclusion list. Keep Matplotlib import errors separate from pyplot, and retain the invalid-transform test with a targeted type ignore.

The author reports that type checks, formatting checks, and the debug utility tests passed (11 tests).

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 54e8eb66-de69-4897-8ee7-9e164d47e964
📥 Commits

Reviewing files that changed from the base of the PR and between c725399 and 0c966b1.

📒 Files selected for processing: 2
  • pyproject.toml
  • tests/utils/test_debug.py
💤 Files with no reviewable changes: 1
  • pyproject.toml

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

📝 Walkthrough

The debug utility stores Matplotlib import failures separately and retrieves pyplot when plotting. The changes add annotations to the plotting function, transform parameter, and tests. Mypy no longer excludes the utility or its tests.

Changes: Debug utility

Layer / File(s) Summary
Pyplot import and plotting access
lightly/utils/debug.py, tests/utils/test_debug.py
The module stores pyplot or its import error. The plotting function retrieves pyplot through a helper and uses it to create the figure and subplots. Tests check Matplotlib availability through importlib.
Transform annotations and type checking
lightly/utils/debug.py, pyproject.toml, tests/utils/test_debug.py
The transform parameter gains an Any annotation, while the existing transform dispatch remains in place. Mypy exclusions are removed, and test helpers and methods gain annotations.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: philippmwirth, sauravmaheshkar

Merge Risk: ⚪ Minimal · up to 0c966

The optional Matplotlib behavior is preserved, and no actionable merge-blocking regression is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding type annotations to the debug utilities.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant