mirror of https://github.com/astral-sh/ruff
[ty] Exclude @Todo types from `assert_{type,never}` checks
This commit is contained in:
parent
f317a71682
commit
55fbc7de0d
|
|
@ -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)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue