From 3821bdd3986dbddee5dfe244a478654e8ca73132 Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Sat, 25 Apr 2026 12:44:19 +0900 Subject: [PATCH] fix --- pyrefly/lib/alt/special_calls.rs | 12 +++++++++++- pyrefly/lib/test/simple.rs | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pyrefly/lib/alt/special_calls.rs b/pyrefly/lib/alt/special_calls.rs index 6db8484664..91dba8ee04 100644 --- a/pyrefly/lib/alt/special_calls.rs +++ b/pyrefly/lib/alt/special_calls.rs @@ -60,7 +60,17 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { TypeFormContext::FunctionArgument, errors, )); - if !self.is_equivalent(&a, &b) { + let matches_metaclass_instance = match (&a, &b) { + (Type::ClassDef(got), Type::ClassType(want)) => { + !want.is_builtin("type") && self.type_order().has_metaclass(got, want) + } + (Type::Type(box Type::ClassType(got)), Type::ClassType(want)) => { + !want.is_builtin("type") + && self.type_order().has_metaclass(got.class_object(), want) + } + _ => false, + }; + if matches_metaclass_instance || !self.is_equivalent(&a, &b) { self.error( errors, range, diff --git a/pyrefly/lib/test/simple.rs b/pyrefly/lib/test/simple.rs index 37b30b27f5..77f9c7af7e 100644 --- a/pyrefly/lib/test/simple.rs +++ b/pyrefly/lib/test/simple.rs @@ -1185,6 +1185,16 @@ assert_type(A, type[A]) "#, ); +testcase!( + test_assert_type_metaclass, + r#" +from typing import assert_type +class Meta(type): pass +class A(metaclass=Meta): pass +assert_type(A, Meta) # E: assert_type(type[A], Meta) failed + "#, +); + testcase!( test_compare_int_str_error, r#"