From 31e6576971aa95354ec39f58ca886cd0a67bffdd Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 29 Apr 2025 13:35:53 +0100 Subject: [PATCH] [red-knot] micro-optimise `ClassLiteral::is_protocol` (#17703) --- crates/red_knot_python_semantic/src/types/class.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/red_knot_python_semantic/src/types/class.rs b/crates/red_knot_python_semantic/src/types/class.rs index b3c28473fc..0a48704475 100644 --- a/crates/red_knot_python_semantic/src/types/class.rs +++ b/crates/red_knot_python_semantic/src/types/class.rs @@ -534,7 +534,7 @@ impl<'db> ClassLiteral<'db> { /// Determine if this class is a protocol. pub(super) fn is_protocol(self, db: &'db dyn Db) -> bool { - self.explicit_bases(db).iter().any(|base| { + self.explicit_bases(db).iter().rev().take(3).any(|base| { matches!( base, Type::KnownInstance(KnownInstanceType::Protocol)