Special-case `is_protocol()` for `str`

This commit is contained in:
Alex Waygood 2025-04-28 15:04:54 +01:00
parent 21b36b015d
commit e55c9e80c9
1 changed files with 6 additions and 0 deletions

View File

@ -145,6 +145,12 @@ impl<'db> ClassType<'db> {
}
pub(super) fn is_protocol(self, db: &'db dyn Db) -> bool {
// `str` requires some special-casing here because in order to construct the type "instance of `str`"
// we must evaluate a call to `TypeVar.__new__`, and `TypeVar.__new__` has a parameter annotated with `str`,
// causing a Salsa cycle.
if self.is_known(db, KnownClass::Str) {
return false;
}
self.class_literal(db).0.is_protocol(db)
}