[red-knot] Fix some instance-attribute TODOs around `ModuleType` (#15974)

This commit is contained in:
Alex Waygood 2025-02-05 15:33:37 +00:00 committed by GitHub
parent 3f958a9d4c
commit c816542704
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 7 deletions

View File

@ -56,10 +56,10 @@ inside the module:
import typing
reveal_type(typing.__name__) # revealed: str
reveal_type(typing.__init__) # revealed: Literal[__init__]
reveal_type(typing.__init__) # revealed: @Todo(bound method)
# These come from `builtins.object`, not `types.ModuleType`:
reveal_type(typing.__eq__) # revealed: Literal[__eq__]
reveal_type(typing.__eq__) # revealed: @Todo(bound method)
reveal_type(typing.__class__) # revealed: Literal[ModuleType]

View File

@ -264,9 +264,7 @@ pub(crate) fn global_symbol<'db>(db: &'db dyn Db, file: File, name: &str) -> Sym
.iter()
.any(|module_type_member| &**module_type_member == name)
{
// TODO: this should use `.to_instance(db)`. but we don't understand attribute access
// on instance types yet.
KnownClass::ModuleType.to_class_literal(db).member(db, name)
KnownClass::ModuleType.to_instance(db).member(db, name)
} else {
Symbol::Unbound
}
@ -3810,8 +3808,7 @@ impl<'db> ModuleLiteralType<'db> {
if name == "__getattr__" {
Symbol::Unbound
} else {
// TODO: this should use `.to_instance()`, but we don't understand instance attribute yet
KnownClass::ModuleType.to_class_literal(db).member(db, name)
KnownClass::ModuleType.to_instance(db).member(db, name)
}
})
}