No Liskov violation reported in a situation where a non-generic method overrides a generic method
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
Pyright does not report a Liskov violation on this code, whereas mypy and pyrefly both do:
```py
class A1:
def method[T: int](self, x: T) -> T:
return x
class B1(A1):
def method(self, x: int) -> int:
return int(x)
```
This means that pyright reports no errors on this larger snippet, and reveals the type on the final line as being `bool`, when in fact it is an `int` at runtime:
```py
class A1:
def method[T: int](self, x: T) -> T:
return x
class B1(A1):
def method(self, x: int) -> int:
return int(x)
def make_me_a_bool(a: A1) -> bool:
return a.method(True)
reveal_type(make_me_a_bool(B1()))
```
**VS Code extension or command-line**
Playground: https://pyright-play.net/?pyrightVersion=1.1.405&pythonVersion=3.12&reportUnreachable=true&code=MYGwhgzhAECCCMAuAUNN0AmBTAZtAtlgC4AWA9hgNoAqi0AlgHZEC6AFBFiDgDTQAedagEpoAWgB80WqnRyATsQCu8xgOTJQkGACF4bBMJRzseQqQocuvAXSZFRkhs2Nz0ioirX22-YRtMCMABrLAB9QjCwMIAjMjIQNjA6Q3EpOITXNA8vaDAAOnNyDDZqeSUsf2RFADcsMBAwogBPAAcsNnwQ8MjojMS9NmFh5CA
Contributor guide
Research direction
Start with the supplied Pyright Playground reproductions and compare the diagnostics and revealed type with mypy and pyrefly. The issue is done when Pyright reports the invalid override and no longer infers bool for the larger example's final result.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100