Error disappears when just checking the erroneous file
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
I am encountering a weird error that when I check a whole module, an error is issued, but when I only check the affected file, the error disappears. [demo.zip](https://github.com/user-attachments/files/27795802/demo.zip)
```bash
(3.14) rscholz@Z890:/tmp$ pyright demo/
/tmp/demo/vectors.py
/tmp/demo/vectors.py:14:34 - error: Cannot assign to attribute "KNOWN_MEETS" for class "type[Vecs]"
"Meet[VectorDomain]" is not assignable to "Meet[Self@Poset]"
Type parameter "D@Meet" is covariant, but "VectorDomain" is not a subtype of "Self@Poset"
"VectorDomain" is not assignable to "Poset" (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations
(3.14) rscholz@Z890:/tmp$ pyright demo/vectors.py
0 errors, 0 warnings, 0 informations
```
```python
# file demo/__init__.py
```
```python
# file demo/base.py
from enum import Enum
from typing import ClassVar, Protocol, Self
class DomainLike(Protocol): ...
class Domain(DomainLike, Protocol):
def __and__(self, other, /) -> Domain: ...
class Meet[D: DomainLike](Domain):
def __and__(self, other: DomainLike, /) -> Meet: ...
class VectorDomain(Domain):
def __and__(self, other: Self, /) -> Meet[VectorDomain]: ...
class Poset(Enum):
KNOWN_MEETS: ClassVar[tuple[tuple[Self, Meet[Self]], ...]]
```
```python
# file vectors.py
from .base import Poset, VectorDomain
class Empty(VectorDomain): ...
class Negative(VectorDomain): ...
class NonNegative(VectorDomain): ...
class Vecs(VectorDomain, Poset):
EMPTY = Empty() # bottom node
NEGATIVE = Negative() # xᵢ < 0
NONNEGATIVE = NonNegative() # xᵢ ≥ 0
Vecs.KNOWN_MEETS = ((Vecs.EMPTY, Vecs.NEGATIVE & Vecs.NONNEGATIVE),)
```
Contributor guide
Research direction
Start by extracting demo.zip and running pyright demo/ and pyright demo/vectors.py to reproduce the differing diagnostics. Inspect demo/base.py and demo/vectors.py, focusing on the generic types, Self annotations, and cross-file imports. Done means the whole-module and single-file checks report consistently for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100