Pyright 1.1.410 rejects jaxtyping instance attribute shape annotation as Literal[3]
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
Pyright 1.1.410 reports an error for a jaxtyping instance attribute annotation that was accepted by Pyright 1.1.407.
The error appears when a `jaxtyping` array annotation with a single numeric shape string is used directly in a local `self.x` annotation with a union. Pyright appears to interpret the jaxtyping shape string `"3"` as `Literal[3]`, then rejects it as an invalid type expression.
Expected behavior: the annotation should be accepted, as it was in Pyright 1.1.407 and as similar jaxtyping annotations are accepted in function signatures.
Actual behavior with Pyright 1.1.410:
```text
error: Expected class but received "Literal[3]" (reportGeneralTypeIssues)
```
Steps to reproduce:
1. Install `pyright==1.1.410`, `jaxtyping==0.3.9`, and `torch`.
2. Save the code below as `repro.py`.
3. Run `pyright repro.py`.
**Code or Screenshots**
```python
import torch
import jaxtyping as Jt
class A:
def __init__(self) -> None:
self.x: Jt.Float64[torch.Tensor, "3"] | None
```
Observed output with Pyright 1.1.410:
```text
repro.py:7:48 - error: Expected class but received "Literal[3]" (reportGeneralTypeIssues)
```
The issue also reproduces with assignment:
```python
import torch
import jaxtyping as Jt
class A:
def __init__(self) -> None:
self.x: Jt.Float64[torch.Tensor, "3"] | None = None
```
This workaround passes Pyright 1.1.410:
```python
from typing import TYPE_CHECKING, Literal, TypeAlias
import torch
import jaxtyping as Jt
if TYPE_CHECKING:
TensorVec3F64: TypeAlias = Jt.Float64[torch.Tensor, "3"]
class A:
def __init__(self) -> None:
self.x: TensorVec3F64 | None
```
Installed third-party versions used to reproduce:
```text
jaxtyping==0.3.9
torch installed
```
**VS Code extension or command-line**
Command-line tool.
```text
pyright 1.1.410
```
This passed with:
```text
pyright 1.1.407
```
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
Use the repro.py examples and run them with Pyright 1.1.410, comparing the result with 1.1.407. Trace how the instance attribute annotation is interpreted, then add regression coverage for the jaxtyping shape string used with a union; done means pyright accepts the annotation without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100