Skip to content

Add missing type hints#367

Merged
ValerianRey merged 4 commits intomainfrom
add-type-hints
Jun 2, 2025
Merged

Add missing type hints#367
ValerianRey merged 4 commits intomainfrom
add-type-hints

Conversation

@ValerianRey
Copy link
Copy Markdown
Contributor

@ValerianRey ValerianRey commented May 29, 2025

This PR adds type hint when it's not possible for mypy to infer them: when an empty structure is created before being filled (note that mypy is able to infer the type in this case but only when the structure is filled with simple .append calls - here we use dict union or our add function), and when a Select transform is created.

The thing is that when creating a Select transform, there is no way for mypy to know whether it's a selection of Gradients, of Jacobians, or of something else. Also, we can directly specify the type of the Select transform right after the class name when instantiating it, which is what I used there.

  • Add type hint to union in _stack
  • Add type hint to result in _get_descendant_accumulate_grads
  • Be more specific about the type of Select when instantiating it

Note that this is required to avoid some mypy errors.

@ValerianRey ValerianRey added the cc: style Conventional commit type for minor style changes. label May 29, 2025
@ValerianRey ValerianRey self-assigned this May 29, 2025
@ValerianRey ValerianRey added the cc: style Conventional commit type for minor style changes. label May 29, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented May 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/torchjd/_autojac/_mtl_backward.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_transform/_stack.py 100.00% <100.00%> (ø)
src/torchjd/_autojac/_utils.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey ValerianRey mentioned this pull request May 29, 2025
@ValerianRey ValerianRey changed the title Add type hints Add missing type hints May 29, 2025
@ValerianRey ValerianRey mentioned this pull request May 29, 2025
1 task
@ValerianRey ValerianRey merged commit 28405e9 into main Jun 2, 2025
16 checks passed
@ValerianRey ValerianRey deleted the add-type-hints branch June 2, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: style Conventional commit type for minor style changes. package: autojac

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants