Tuple comparison does not check comparability of element types
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When comparing tuples, the comparability of the element isn't taken into account.
To Reproduce
from typing import *
class SupportsGT(Protocol):
def __gt__(self, other: Any, /) -> bool:
...
a = cast(tuple[SupportsGT, ...], ...)
b = cast(tuple[object, ...], ...)
c = a < b # no issue!
Expected Behavior
There is no matching a_elem.__lt__(b_elem) so this should fail.
Actual Behavior
No error.
Your Environment
Python 3.12
Mypy 1.19.1
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
Start with the Python 3.12 reproduction in the issue and trace mypy's tuple-comparison type checking. Add a regression test showing that incompatible element comparisons are rejected, then run the relevant test suite to confirm the expected error is reported.
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