Skip to content

Tuple comparison does not check comparability of element types #21042

@ktbarrett

Description

@ktbarrett

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions