[ty] Exhaustiveness checking for generic classes (#21726)

## Summary

We had tests for this already, but they used generic classes that were
bivariant in their type parameter, and so this case wasn't captured.

closes https://github.com/astral-sh/ty/issues/1702

## Test Plan

Updated Markdown tests
This commit is contained in:
David Peter 2025-12-01 13:52:36 +01:00 committed by GitHub
parent 3a11e714c6
commit 5358ddae88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -284,10 +284,17 @@ python-version = "3.12"
```py ```py
from typing import assert_never from typing import assert_never
class A[T]: ... class A[T]:
value: T
class ASub[T](A[T]): ... class ASub[T](A[T]): ...
class B[T]: ...
class C[T]: ... class B[T]:
value: T
class C[T]:
value: T
class D: ... class D: ...
class E: ... class E: ...
class F: ... class F: ...

View File

@ -336,6 +336,7 @@ fn pattern_kind_to_type<'db>(db: &'db dyn Db, kind: &PatternPredicateKind<'db>)
infer_expression_type(db, *class_expr, TypeContext::default()) infer_expression_type(db, *class_expr, TypeContext::default())
.to_instance(db) .to_instance(db)
.unwrap_or(Type::Never) .unwrap_or(Type::Never)
.top_materialization(db)
} else { } else {
Type::Never Type::Never
} }