[ty] Exclude @Todo types from `assert_{type,never}` checks

This commit is contained in:
David Peter 2025-11-24 14:05:48 +01:00
parent f317a71682
commit 55fbc7de0d
2 changed files with 10 additions and 7 deletions

View File

@ -124,10 +124,6 @@ def match_singletons_error(obj: Literal[1, "a"] | None):
case None:
pass
case _ as obj:
# TODO: We should emit an error here, but the message should
# show the type `Literal["a"]` instead of `@Todo(…)`. We only
# assert on the first part of the message because the `@Todo`
# message is not available in release mode builds.
# error: [type-assertion-failure] "Type `@Todo"
# TODO: We should emit an error here: `Literal["a"]` is not `Never`.
assert_never(obj)
```

View File

@ -1358,6 +1358,8 @@ impl KnownFunction {
let db = context.db();
let parameter_types = overload.parameter_types();
let is_todo_type = |ty: Type<'db>| ty.is_todo();
match self {
KnownFunction::RevealType => {
let revealed_type = overload
@ -1391,7 +1393,10 @@ impl KnownFunction {
let [Some(actual_ty), Some(asserted_ty)] = parameter_types else {
return;
};
if actual_ty.is_equivalent_to(db, *asserted_ty) {
if actual_ty.is_equivalent_to(db, *asserted_ty)
|| any_over_type(db, *actual_ty, &is_todo_type, true)
|| any_over_type(db, *asserted_ty, &is_todo_type, true)
{
return;
}
if let Some(builder) = context.report_lint(&TYPE_ASSERTION_FAILURE, call_expression)
@ -1427,7 +1432,9 @@ impl KnownFunction {
let [Some(actual_ty)] = parameter_types else {
return;
};
if actual_ty.is_equivalent_to(db, Type::Never) {
if actual_ty.is_equivalent_to(db, Type::Never)
|| any_over_type(db, *actual_ty, &is_todo_type, true)
{
return;
}
if let Some(builder) = context.report_lint(&TYPE_ASSERTION_FAILURE, call_expression)