ty can infer `Literal[False]` for `Sequence[object] == ()`, even though
the sequence can be an empty tuple. This can also make reachable
branches disappear and hide errors.
Keep comparisons ambiguous when the operands' known classes have a
base/subclass relationship, even if their inherited equality
implementations differ. Apply the same reasoning to literals and
truthiness-narrowed intersections while retaining the default behavior
for unrelated classes.
Fixesastral-sh/ty#4377.
## Test plan
Added mdtests cover sequence comparisons with empty and nonempty tuples,
strings, bytes, and `LiteralString`; both operand orders and equality
operators; partial generic overlap; and custom base/tuple subclass
relationships. Narrowing regressions check branch reachability and
preserve tuple-comparison and membership precision for unrelated types.
The added Ibis diagnostics in the ecosystem are correct.
## Summary
We already infer equality results for literal values of the same kind,
but mismatched literal kinds fell through to dunder lookup and produced
`bool`. As a result, direct comparisons such as `1 == ""` remained
ambiguous, as did tuple comparisons whose corresponding elements had
different literal kinds.
This adds a narrow expression-inference case for mismatched built-in
`int`, `bool`, `str`, and `bytes` literals. It also handles
`LiteralString` compared with non-string literals while preserving
`bool` for `LiteralString` compared with a particular string literal,
since those values may be equal.
```python
reveal_type(1 == "") # Literal[False]
reveal_type(True != "") # Literal[True]
left = (1, 2)
right = (1, "two")
reveal_type(left == right) # Literal[False]
```
---------
Co-authored-by: Carl Meyer <carl@astral.sh>