patrick-kidger / patrick-kidger/jaxtyping
mypy type checking seems to break in strict mode -- a mypy bug?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Description
Following up on https://github.com/patrick-kidger/torchtyping/issues/41 I'm trying the same things here. However I'm not really having a big success so far with mypy. Am I doing anything wrong?
import torch
from jaxtyping import Float
dim1 = "dim1"
# Expected to work but fails with:
# error: Returning Any from function declared to return "Tensor"
def simple_test_a(x: Float[torch.Tensor, "dim1"]) -> torch.Tensor:
return x
# Expected to work but fails with:
# error: Returning Any from function declared to return "float"
def simple_test_b(x: Float[torch.Tensor, "dim1"]) -> float:
return x.item()
# Expected to error, but passes type checking
def simple_test_c(x: Float[torch.Tensor, "dim1"]) -> None:
x.asdfasdfasdf()
VSCode (pyright) seems to do a little better, but apparently doesn't like the import:

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the three snippets from the issue with mypy in strict mode, then compare the reported behavior with pyright. Determine whether the failures come from jaxtyping, PyTorch typing, or the type checkers; done means identifying the cause and documenting or fixing the relevant behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100