Skip to content

Commit f8d0350

Browse files
committed
Treat TypeVar as Any for descriptor protocol
1 parent 40d392e commit f8d0350

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

  • crates/red_knot_python_semantic/src

crates/red_knot_python_semantic/src/types.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,13 +2046,17 @@ impl<'db> Type<'db> {
20462046
);
20472047

20482048
let custom_getattr_result = || {
2049-
// Typeshed has a fake `__getattr__` on `types.ModuleType` to help out with dynamic imports.
2050-
// We explicitly hide it here to prevent arbitrary attributes from being available on modules.
2051-
if self
2052-
.into_instance()
2053-
.is_some_and(|instance| instance.class.is_known(db, KnownClass::ModuleType))
2054-
{
2055-
return Symbol::Unbound.into();
2049+
if let Some(instance) = self.into_instance() {
2050+
match instance.class.known(db) {
2051+
// Typeshed has a fake `__getattr__` on `types.ModuleType` to help out with dynamic imports.
2052+
// We explicitly hide it here to prevent arbitrary attributes from being available on modules.
2053+
Some(KnownClass::ModuleType) => return Symbol::Unbound.into(),
2054+
2055+
// TODO: For now we are treating a TypeVar as Any.
2056+
Some(KnownClass::TypeVar) => return Symbol::bound(Type::any()).into(),
2057+
2058+
_ => {}
2059+
}
20562060
}
20572061

20582062
self.try_call_dunder(

0 commit comments

Comments
 (0)