Skip to content
Open
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
12 changes: 11 additions & 1 deletion pyrefly/lib/alt/special_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment on lines +63 to +73
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matches_metaclass_instance is a boolean that triggers the error path when true, so the name reads as if it's a success condition even though it represents a mismatch case. Consider renaming it (e.g., is_metaclass_assert_mismatch / metaclass_instance_mismatch) or inverting the boolean so the if condition reads more directly.

Copilot uses AI. Check for mistakes.
self.error(
errors,
range,
Expand Down
10 changes: 10 additions & 0 deletions pyrefly/lib/test/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down
Loading