File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
crates/red_knot_python_semantic Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -1299,12 +1299,9 @@ class FalsyFooSubclass(FalsyFoo, Protocol):
12991299 y: str
13001300
13011301def g (a : Truthy, b : FalsyFoo, c : FalsyFooSubclass):
1302- # TODO should be `Literal[True]
1303- reveal_type(bool (a)) # revealed: bool
1304- # TODO should be `Literal[False]
1305- reveal_type(bool (b)) # revealed: bool
1306- # TODO should be `Literal[False]
1307- reveal_type(bool (c)) # revealed: bool
1302+ reveal_type(bool (a)) # revealed: Literal[True]
1303+ reveal_type(bool (b)) # revealed: Literal[False]
1304+ reveal_type(bool (c)) # revealed: Literal[False]
13081305```
13091306
13101307It is not sufficient for a protocol to have a callable ` __bool__ ` instance member that returns
Original file line number Diff line number Diff line change @@ -145,6 +145,16 @@ impl<'db> ClassType<'db> {
145145 }
146146
147147 pub ( super ) fn is_protocol ( self , db : & ' db dyn Db ) -> bool {
148+ // We need to construct the types "instance of `str`" and "instance of `_version_info`"
149+ // very eagerly when type-checking a variety of things. That means we can't go through the normal
150+ // `ClassLiteral::is_protocol` path, because that would require us to evaluate the types of the bases
151+ // of these classes, which would cause Salsa cycles (or other, more exotic kinds of Salsa panics!).
152+ if matches ! (
153+ self . known( db) ,
154+ Some ( KnownClass :: Str | KnownClass :: VersionInfo )
155+ ) {
156+ return false ;
157+ }
148158 self . class_literal ( db) . 0 . is_protocol ( db)
149159 }
150160
You can’t perform that action at this time.
0 commit comments