[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: case None:
pass pass
case _ as obj: case _ as obj:
# TODO: We should emit an error here, but the message should # TODO: We should emit an error here: `Literal["a"]` is not `Never`.
# 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"
assert_never(obj) assert_never(obj)
``` ```

View File

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