mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
[red-knot] Precise inference for __class__
attributes on objects of all types (#14921)
This commit is contained in:
parent
a54353392f
commit
c361cf66ad
3 changed files with 45 additions and 5 deletions
|
@ -1272,6 +1272,10 @@ impl<'db> Type<'db> {
|
|||
/// as accessed from instances of the `Bar` class.
|
||||
#[must_use]
|
||||
pub(crate) fn member(&self, db: &'db dyn Db, name: &str) -> Symbol<'db> {
|
||||
if name == "__class__" {
|
||||
return self.to_meta_type(db).into();
|
||||
}
|
||||
|
||||
match self {
|
||||
Type::Any => Type::Any.into(),
|
||||
Type::Never => {
|
||||
|
@ -2697,10 +2701,6 @@ impl<'db> Class<'db> {
|
|||
return Type::tuple(db, &tuple_elements).into();
|
||||
}
|
||||
|
||||
if name == "__class__" {
|
||||
return self.metaclass(db).into();
|
||||
}
|
||||
|
||||
for superclass in self.iter_mro(db) {
|
||||
match superclass {
|
||||
// TODO we may instead want to record the fact that we encountered dynamic, and intersect it with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue