KotlinIsland / KotlinIsland/basedmypy

unsafe variance errors shouldn't propagate down

Open
#61 0 comments 0 reactions 0 assignees View on GitHub
bug p-2
Dominant language
Python
Stars
202
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Same thing with unsafe variance in protocol inheritance:
```py
from typing import Protocol, _T_co as T_co

class A(Protocol[T_co]): # type: ignore
def foo(self, t: T_co) -> None: ... # type: ignore

class B(A[T_co], Protocol): # ERROR! using covariant type variable where invariant one expected!!!
def bar(self) -> T_co: ...
```

[playground](https://mypy-play.net/?gist=f763a37b161f534caa8a76e67ff24757)

Contributor guide

Open the contributing guide

Research direction

Start with the minimal Python reproduction in the issue and compare its diagnostics with the linked mypy-play playground. Trace protocol inheritance and unsafe-variance checking to determine why the error propagates into B; done means the shown inheritance pattern no longer reports the unwanted error while preserving the relevant variance checks.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.