Skip to content

Type checking harness + fix invalid-argument-type errors#113

Merged
vinamarora8 merged 30 commits intomainfrom
vinam/typechecking
Mar 23, 2026
Merged

Type checking harness + fix invalid-argument-type errors#113
vinamarora8 merged 30 commits intomainfrom
vinam/typechecking

Conversation

@vinamarora8
Copy link
Copy Markdown
Member

@vinamarora8 vinamarora8 commented Mar 22, 2026

This PR:

1) Adds a type-checking CI action that will show an error if typing rules are violated in a PR (example error). It uses Astral's ty* under the hood (same folks that made uv).

2) Clears all invalid-argument-type errors. And so, only this error is enabled at the moment. We can enable others as we solve them in the existing codebase

This starts to address #65 but will need more work to fully close.


*Other typecheckers: I tried pyright, mypy, and pyrefly as well, but ty seemed to be the one I most agreed with and it has the most readable error log. All type-checkers are opinionated at the end of the day. ty is in beta stage, so we are taking some small risk when going with it. But it's Astral; they have delivered quite well in the past with uv. Worst case: we have to move to another type checker in the future; should be an easy job for a coding agent.

Summary by CodeRabbit

  • Chores

    • Added automated type checking to CI.
    • Updated development dependencies to include a type checker.
    • Improved type annotations across core time-series and array utilities for safer static checks.
  • Tests

    • Adjusted a unit test to remain functionally equivalent while accommodating stricter static typing.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 22, 2026

Warning

Rate limit exceeded

@vinamarora8 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 42 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffd21ede-9c00-46ac-9f5a-f8cf7d8b2061

📥 Commits

Reviewing files that changed from the base of the PR and between 7106875 and 784adc0.

📒 Files selected for processing (2)
  • README.md
  • pyproject.toml
📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow to run the ty type checker on pushes to main and pull requests, updates pyproject to include and configure ty, refines several constructor type annotations in core modules, and adjusts a test to suppress a type-checker complaint.

Changes

Cohort / File(s) Summary
CI Workflow Configuration
.github/workflows/typecheck.yml
New GitHub Actions workflow that checks out code, creates a Python 3.10 venv, installs .[dev], and runs ty check --output-format github on pushes to main and on PRs.
Project config / Ty settings
pyproject.toml
Added ty==0.0.24 to project.optional-dependencies.dev; added [tool.ty.environment] (python-version = "3.10"), [tool.ty.src] (include temporaldata, tests), and [tool.ty.rules] (sets invalid-argument-type = "error", others ignored).
Type annotations — constructors
temporaldata/arraydict.py, temporaldata/interval.py, temporaldata/irregular_ts.py, temporaldata/regular_ts.py
Standardized variadic kwarg annotations from Dict[str, np.ndarray]np.ndarray. Made IrregularTimeSeries.timekeys type `List[str]
Tests
tests/test_arraydict.py
Adjusted test call-site formatting and added # ty: ignore[invalid-argument-type] to suppress Ty diagnostics while keeping runtime assertion behavior unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 I hopped through code with careful cheer,
Added Ty to keep types clear,
Workflows hum and tests still play,
Annotations guide the way! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding a type-checking CI workflow and fixing type annotation errors related to invalid-argument-type violations.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vinam/typechecking

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 22, 2026

Benchmark comparison vs main

Baseline: origin/main
Target: HEAD

Running benchmarks for 25cd6578c0...
Running benchmarks for 784adc0777...

  Benchmark                                     25cd6578c0 (µs)    784adc0777 (µs)    Speedup
  --------------------------------------------------------------------------------------------
  Data.slice() (lazy, realistic)                       1925.196           1889.779      1.02x
  Data.slice() (in-memory)                              748.330            744.598      1.01x
  IrregularTimeSeries.slice()                            87.636             88.006      1.00x
  RegularTimeSeries.slice()                              44.565             45.036      0.99x
  Interval.slice()                                        9.276              9.365      0.99x
  Interval.__and__ (1k&single)                           51.413             46.067      1.12x
  Interval.__and__ (1k&100)                            1200.268            942.713      1.27x
  Interval.__or__ (1k|100)                               65.144             64.960      1.00x
  Interval.difference (1k-100)                         5787.252           5743.718      1.01x
  ArrayDict.keys() x100k                                  1.775              1.785      0.99x
  LazyInterval access (10 attrs)                       2374.962           2313.983      1.03x

@vinamarora8 vinamarora8 changed the title Type checking harness Type checking harness + clear invalid-argument-type errors Mar 22, 2026
@vinamarora8 vinamarora8 changed the title Type checking harness + clear invalid-argument-type errors Type checking harness + fix invalid-argument-type errors Mar 22, 2026
@vinamarora8 vinamarora8 marked this pull request as ready for review March 23, 2026 02:51
Copy link
Copy Markdown
Contributor

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

Adds a ty-based type-checking harness to CI and updates core constructors’ type hints to eliminate invalid-argument-type findings (primarily around **kwargs value types and "auto" domain handling).

Changes:

  • Introduces a new GitHub Action workflow to run ty check on PRs and main pushes.
  • Updates type annotations in ArrayDict, Interval, IrregularTimeSeries, and RegularTimeSeries to better reflect runtime expectations.
  • Adds ty configuration to pyproject.toml and applies a targeted ty ignore in a test that intentionally passes an invalid type.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/test_arraydict.py Adds a targeted ty ignore to keep a negative test while enforcing invalid-argument-type globally.
temporaldata/arraydict.py Tightens **kwargs annotation to value-type (np.ndarray) to match runtime assertions.
temporaldata/interval.py Tightens **kwargs annotation to np.ndarray for consistency with ArrayDict’s runtime checks.
temporaldata/irregular_ts.py Makes timekeys explicitly optional and aligns **kwargs typing with ArrayDict.
temporaldata/regular_ts.py Adds "auto" to the domain type and aligns **kwargs typing with ArrayDict.
pyproject.toml Adds ty to dev deps and configures rules + source roots for type checking.
.github/workflows/typecheck.yml New CI workflow to run ty check and annotate PRs with typing failures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/typecheck.yml
Comment thread temporaldata/regular_ts.py Outdated
Comment thread temporaldata/regular_ts.py
Comment thread temporaldata/regular_ts.py
Comment thread pyproject.toml Outdated
Comment thread tests/test_arraydict.py
Copy link
Copy Markdown

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
temporaldata/regular_ts.py (1)

24-25: ⚠️ Potential issue | 🟡 Minor

Docstring contradicts implementation.

Line 25 states "It is not possible to set domain to :obj:\"auto\"", but the type annotation on line 57 now includes Literal["auto"] and the implementation at lines 65-73 explicitly handles domain == "auto". The docstring should be updated to reflect the actual behavior.

📝 Suggested fix
     Args:
         sampling_rate: Sampling rate in Hz.
         domain: an :obj:`Interval` object that defines the domain over which the
-            timeseries is defined. It is not possible to set domain to :obj:`"auto"`.
+            timeseries is defined. If set to :obj:`"auto"`, the domain will be
+            automatically computed from the data length and sampling rate.
         **kwargs: Arbitrary keyword arguments where the values are arbitrary
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@temporaldata/regular_ts.py` around lines 24 - 25, The docstring incorrectly
forbids domain="auto" despite the type annotation (includes Literal["auto"]) and
implementation handling domain == "auto" on lines where the domain param is
processed; update the parameter description for domain to state it accepts
either an Interval or the string "auto" and document that passing "auto"
triggers automatic domain inference/creation (match the behavior implemented in
the domain handling code around the domain type annotation and the domain ==
"auto" branch).
🧹 Nitpick comments (2)
.github/workflows/typecheck.yml (1)

1-31: LGTM!

The workflow correctly sets up Python 3.10 with uv, installs dev dependencies, and runs the ty type checker with GitHub-formatted output for inline annotations.

Consider simplifying the workflow by using uv run which handles virtual environment management automatically:

♻️ Optional simplification
       - name: Install project
         run: |
-          uv venv venv -p 3.10
-          source venv/bin/activate
-          uv pip install -e ".[dev]"
+          uv pip install -e ".[dev]" --python 3.10

       - name: Run ty
         run: |
-          source venv/bin/activate
-          ty check --output-format github
+          uv run ty check --output-format github
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/typecheck.yml around lines 1 - 31, The workflow works but
can be simplified by using uv's built-in runner instead of manually
creating/activating a venv; replace the steps that call "uv venv venv -p 3.10"
and "source venv/bin/activate" plus the separate "uv pip install -e '.[dev]'"
and "ty check" invocation with a single uv run invocation that runs the type
checker in a managed environment (so remove the manual venv creation/activation
and direct ty call and instead run ty via uv run, keeping the job name
"typecheck" and step names like "Install project"/"Run ty" recognizable for
locating the change).
pyproject.toml (1)

26-26: Consider pinning the ty version.

Since ty is in beta (latest version is 0.0.24), an unpinned dependency could cause unexpected CI failures if a new ty release introduces breaking changes or new diagnostics. Consider specifying a version constraint such as ty<1 to allow patch updates within the 0.0.x series while preventing major version breaks.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pyproject.toml` at line 26, The dev dependency list currently includes an
unpinned "ty" which can introduce CI instability; update the entry in
pyproject.toml's dev = [...] list to constrain the "ty" package (e.g., change
"ty" to "ty<1" or pin to a specific known-good release like "ty==0.0.24") so
that the dev dependencies for the project are stable; locate the "dev" array
containing "pytest<9", "black==24.2.0", "pre-commit>=3.5.0", "flake8",
"pytest-cov", "ty" and replace the "ty" token with the chosen version
constraint.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@temporaldata/regular_ts.py`:
- Around line 24-25: The docstring incorrectly forbids domain="auto" despite the
type annotation (includes Literal["auto"]) and implementation handling domain ==
"auto" on lines where the domain param is processed; update the parameter
description for domain to state it accepts either an Interval or the string
"auto" and document that passing "auto" triggers automatic domain
inference/creation (match the behavior implemented in the domain handling code
around the domain type annotation and the domain == "auto" branch).

---

Nitpick comments:
In @.github/workflows/typecheck.yml:
- Around line 1-31: The workflow works but can be simplified by using uv's
built-in runner instead of manually creating/activating a venv; replace the
steps that call "uv venv venv -p 3.10" and "source venv/bin/activate" plus the
separate "uv pip install -e '.[dev]'" and "ty check" invocation with a single uv
run invocation that runs the type checker in a managed environment (so remove
the manual venv creation/activation and direct ty call and instead run ty via uv
run, keeping the job name "typecheck" and step names like "Install project"/"Run
ty" recognizable for locating the change).

In `@pyproject.toml`:
- Line 26: The dev dependency list currently includes an unpinned "ty" which can
introduce CI instability; update the entry in pyproject.toml's dev = [...] list
to constrain the "ty" package (e.g., change "ty" to "ty<1" or pin to a specific
known-good release like "ty==0.0.24") so that the dev dependencies for the
project are stable; locate the "dev" array containing "pytest<9",
"black==24.2.0", "pre-commit>=3.5.0", "flake8", "pytest-cov", "ty" and replace
the "ty" token with the chosen version constraint.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3638210b-d673-4ee7-8f4d-52b31bfb507c

📥 Commits

Reviewing files that changed from the base of the PR and between 25cd657 and 2895b98.

📒 Files selected for processing (7)
  • .github/workflows/typecheck.yml
  • pyproject.toml
  • temporaldata/arraydict.py
  • temporaldata/interval.py
  • temporaldata/irregular_ts.py
  • temporaldata/regular_ts.py
  • tests/test_arraydict.py

Copy link
Copy Markdown
Contributor

@milosobral milosobral left a comment

Choose a reason for hiding this comment

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

I think this is great! We should probably also add this to torch_brain and brainsets

@vinamarora8 vinamarora8 merged commit 91e6437 into main Mar 23, 2026
10 checks passed
@vinamarora8 vinamarora8 deleted the vinam/typechecking branch March 23, 2026 15:07
vinamarora8 added a commit to neuro-galaxy/torch_brain that referenced this pull request Apr 19, 2026
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.

3 participants