SIGN IN SIGN UP
astral-sh / ruff UNCLAIMED

An extremely fast Python linter and code formatter, written in Rust.

0 0 37 Rust

[ty] Add help message to invalid-generic-class variance diagnostic (#25385)

## Summary

When a generic subclass uses an explicitly-declared TypeVar in a base
class position where the variance is incompatible, the existing
diagnostic only reported which type variable and base class were
involved:

Variance of type variable `T_co` is incompatible with base class
`Invariant`

This adds a `.help()` sub-diagnostic that explains *why* it is
incompatible and what the base class actually requires:

Type variable `T_co` is declared as covariant, but base class
`Invariant` requires it to be invariant


## Test Plan

Added a new mdtest section in
`crates/ty_python_semantic/resources/mdtest/generics/legacy/variance.md`
covering all four incompatible variance combinations, verifying the
exact diagnostic message text.

---------

Co-authored-by: David Peter <mail@david-peter.de>
D
Dev-X25874 committed
dfb5e926cbd2e787dca56b925754ccc3f87ed97f
Parent: 6aaa91a
Committed by GitHub <noreply@github.com> on 5/27/2026, 12:27:44 PM