Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
11 changes: 9 additions & 2 deletions crates/ty_python_semantic/src/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down