mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:14:52 +00:00
[ty] Enforce that an attribute on a class X
must be callable in order to satisfy a member on a protocol P
(#20142)
## Summary Small, incremental progress towards checking the types of method members. ## Test Plan Added an mdtest
This commit is contained in:
parent
4ca38b2974
commit
0d7ed32494
2 changed files with 6 additions and 1 deletions
|
@ -1704,7 +1704,11 @@ class NotSubtype:
|
||||||
def m(self, x: int) -> int:
|
def m(self, x: int) -> int:
|
||||||
return 42
|
return 42
|
||||||
|
|
||||||
|
class DefinitelyNotSubtype:
|
||||||
|
m = None
|
||||||
|
|
||||||
static_assert(is_subtype_of(NominalSubtype, P))
|
static_assert(is_subtype_of(NominalSubtype, P))
|
||||||
|
static_assert(not is_subtype_of(DefinitelyNotSubtype, P))
|
||||||
|
|
||||||
# TODO: should pass
|
# TODO: should pass
|
||||||
static_assert(not is_subtype_of(NotSubtype, P)) # error: [static-assert-error]
|
static_assert(not is_subtype_of(NotSubtype, P)) # error: [static-assert-error]
|
||||||
|
|
|
@ -560,7 +560,8 @@ impl<'a, 'db> ProtocolMember<'a, 'db> {
|
||||||
db,
|
db,
|
||||||
matches!(
|
matches!(
|
||||||
other.to_meta_type(db).member(db, self.name).place,
|
other.to_meta_type(db).member(db, self.name).place,
|
||||||
Place::Type(_, Boundness::Bound)
|
Place::Type(ty, Boundness::Bound)
|
||||||
|
if ty.is_assignable_to(db, CallableType::single(db, Signature::dynamic(Type::any())))
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// TODO: consider the types of the attribute on `other` for property members
|
// TODO: consider the types of the attribute on `other` for property members
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue