mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Fall back to object
for attribute access on synthesized protocols (#20286)
This commit is contained in:
parent
982a0a2a7c
commit
deb3d3d150
4 changed files with 39 additions and 2 deletions
|
@ -3409,6 +3409,23 @@ impl<'db> Type<'db> {
|
|||
|
||||
Type::ModuleLiteral(module) => module.static_member(db, name_str),
|
||||
|
||||
// If a protocol does not include a member and the policy disables falling back to
|
||||
// `object`, we return `Place::Unbound` here. This short-circuits attribute lookup
|
||||
// before we find the "fallback to attribute access on `object`" logic later on
|
||||
// (otherwise we would infer that all synthesized protocols have `__getattribute__`
|
||||
// methods, and therefore that all synthesized protocols have all possible attributes.)
|
||||
//
|
||||
// Note that we could do this for *all* protocols, but it's only *necessary* for synthesized
|
||||
// ones, and the standard logic is *probably* more performant for class-based protocols?
|
||||
Type::ProtocolInstance(ProtocolInstanceType {
|
||||
inner: Protocol::Synthesized(protocol),
|
||||
..
|
||||
}) if policy.mro_no_object_fallback()
|
||||
&& !protocol.interface().includes_member(db, name_str) =>
|
||||
{
|
||||
Place::Unbound.into()
|
||||
}
|
||||
|
||||
_ if policy.no_instance_fallback() => self.invoke_descriptor_protocol(
|
||||
db,
|
||||
name_str,
|
||||
|
|
|
@ -227,7 +227,7 @@ impl<'db> ProtocolInterface<'db> {
|
|||
place: Place::bound(member.ty()),
|
||||
qualifiers: member.qualifiers(),
|
||||
})
|
||||
.unwrap_or_else(|| Type::object(db).instance_member(db, name))
|
||||
.unwrap_or_else(|| Type::object(db).member(db, name))
|
||||
}
|
||||
|
||||
/// Return `true` if if all members on `self` are also members of `other`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue