From 232fbc13002eaae072fcaa156298da125300bbbd Mon Sep 17 00:00:00 2001 From: InSync Date: Sat, 11 Jan 2025 04:25:59 +0700 Subject: [PATCH] [red-knot] Understand `type[Unknown]` (#15409) ## Summary Follow-up to #15194. ## Test Plan Markdown tests. --- .../resources/mdtest/directives/assert_type.md | 9 +++------ crates/red_knot_python_semantic/src/types/infer.rs | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/red_knot_python_semantic/resources/mdtest/directives/assert_type.md b/crates/red_knot_python_semantic/resources/mdtest/directives/assert_type.md index fe511cb71f..af467121fa 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/directives/assert_type.md +++ b/crates/red_knot_python_semantic/resources/mdtest/directives/assert_type.md @@ -66,14 +66,11 @@ def _(a: Unknown, b: Any): assert_type(b, Unknown) # fine def _(a: type[Unknown], b: type[Any]): - # TODO: Should be `type[Unknown]` - reveal_type(a) # revealed: @Todo(unsupported type[X] special form) - # TODO: Should be fine - assert_type(a, type[Any]) # error: [type-assertion-failure] + reveal_type(a) # revealed: type[Unknown] + assert_type(a, type[Any]) # fine reveal_type(b) # revealed: type[Any] - # TODO: Should be fine - assert_type(b, type[Unknown]) # error: [type-assertion-failure] + assert_type(b, type[Unknown]) # fine ``` ## Tuples diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 7932777c66..4923285adb 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -5066,6 +5066,9 @@ impl<'db> TypeInferenceBuilder<'db> { Type::KnownInstance(KnownInstanceType::Any) => { SubclassOfType::subclass_of_any() } + Type::KnownInstance(KnownInstanceType::Unknown) => { + SubclassOfType::subclass_of_unknown() + } _ => todo_type!("unsupported type[X] special form"), } }