Skip to content

ci: Add mypy to ci and update types in code#25

Merged
FBumann merged 3 commits intomainfrom
feature/mypy
Jan 26, 2026
Merged

ci: Add mypy to ci and update types in code#25
FBumann merged 3 commits intomainfrom
feature/mypy

Conversation

@FBumann
Copy link
Owner

@FBumann FBumann commented Jan 26, 2026

Summary

Adds mypy type checking to CI and fixes all type errors to pass strict mode.

Changes

CI (ci.yml):

  • Added mypy type check step after format check

Type fixes:

  • figures.py: Added proper type parameters for Iterator, list[go.Frame] return types, and dict[str, Any] for kwargs
  • config.py: Used cast() with quoted type strings for restoring options
  • common.py: Added type parameter dict[str, object] for attrs argument
  • plotting.py: Changed np.ndarray to npt.ArrayLike for array-like input
  • __init__.py: Added # type: ignore[no-untyped-call] for xarray's untyped accessor decorators

Test plan

  • mypy xarray_plotly passes with no errors
  • ruff check . passes
  • pytest passes (121 tests)

@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Warning

Rate limit exceeded

@FBumann has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This PR introduces mypy static type checking to the CI workflow and refines type hints throughout the codebase. Changes include narrowing parameter types, adding cast calls for type safety, and clarifying return types for multiple functions, without altering runtime behavior.

Changes

Cohort / File(s) Summary
CI Type Checking
.github/workflows/ci.yml
Adds mypy type check step running on xarray_plotly target, positioned after Format check and before Test step.
Type Annotation Refinement
xarray_plotly/__init__.py
Adds type: ignore annotations on two Plotly accessor registration calls to suppress type checker warnings for untyped external library calls.
Parameter Type Narrowing
xarray_plotly/common.py
Narrows _get_label_from_attrs parameter type from generic dict to dict[str, object] for stricter type checking.
Type Safety with Casts
xarray_plotly/config.py
Imports cast and applies type casts to restored option values in set_options before reassignment for six configuration parameters.
Return Type Clarification
xarray_plotly/figures.py
Expands type hints with Any import; clarifies return types for _iter_all_traces (to Iterator[Any]), _merge_frames and _merge_secondary_y_frames (to list[go.Frame]); refines update_traces signature with generic parameter types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Static types, oh what a sight!
Mypy checks, making code tight,
Casts and hints, all in a row,
Runtime safe, now we know!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main changes: adding mypy type checking to CI and updating type annotations throughout the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@xarray_plotly/config.py`:
- Line 11: The failing TC006 rule is caused by unquoted type expressions passed
to cast() in xarray_plotly/config.py; locate the cast(...) calls that currently
use bool, str, and dict[str, tuple[str, ...]] and replace their type arguments
with string-literal types (e.g., cast("bool", ...), cast("str", ...),
cast("dict[str, tuple[str, ...]]", ...)) so the type expressions are quoted;
ensure you update each cast invocation (search for cast usages around the config
parsing/assignment logic) to use the quoted form.

@FBumann FBumann merged commit 3c1b9d9 into main Jan 26, 2026
9 checks passed
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