Improve truncation logic for Protocol mismatches
Open
Nobody has claimed this yet.
bug
topic-error-reporting
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
https://mypy-play.net/?mypy=latest&python=3.11&gist=430fa5525005889ffb44e2e974a5b67c
from typing import Protocol
class P(Protocol):
def a(self) -> P: ...
def b(self) -> P: ...
def c(self, x: int) -> None: ...
class C:
def a(self) -> C:
return self
def b(self) -> C:
return self
def c(self, x: str) -> None:
return None
def takes_p(p: P) -> None: ...
takes_p(C())
This gives:
main.py:18: error: Argument 1 to "takes_p" has incompatible type "C"; expected "P" [arg-type]
main.py:18: note: Following member(s) of "C" have conflicts:
main.py:18: note: Expected:
main.py:18: note: def a(self) -> P
main.py:18: note: Got:
main.py:18: note: def a(self) -> C
main.py:18: note: Expected:
main.py:18: note: def b(self) -> P
main.py:18: note: Got:
main.py:18: note: def b(self) -> C
main.py:18: note: <1 more conflict(s) not shown>
Found 1 error in 1 file (checked 1 source file)
where the actual cause of the conflict is not shown
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
Reproduce the Protocol mismatch with the linked mypy-play example and inspect how the diagnostic truncates conflicting members. Trace the diagnostic output from this case; done means the message exposes the conflict that currently remains hidden, while retaining appropriate truncation for larger mismatch lists.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100