From 6b94e620fe528ad166854a678792f7445293e07b Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 8 Oct 2025 14:04:37 +0200 Subject: [PATCH] [ty] Fix accidental Liskov violation in protocol tests (#20763) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary We have the following test in `protocols.md`: ```py class HasX(Protocol): x: int # […] class Foo: x: int # […] class FooBool(Foo): x: bool static_assert(not is_subtype_of(FooBool, HasX)) static_assert(not is_assignable_to(FooBool, HasX)) ``` If `Foo` was indeed intended to be a base class of `FooBool`, then `x: bool` should be reported as a Liskov violation. And then it's a matter of definition whether or not these assertions should hold true or not (should the incorrect override take precedence or not?). So it looks to me like this is just an oversight, probably a copy-paste error from another test right before it, where `FooSub` is indeed intended to be a subclass of `Foo`. I am fixing this because this test started to fail on a branch of mine that changes how attribute lookup in inheritance chains works. --- crates/ty_python_semantic/resources/mdtest/protocols.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index 5da379ef86..8db7a8ae6d 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -630,7 +630,7 @@ static_assert(is_assignable_to(FooSub, HasX)) static_assert(not is_subtype_of(FooSub, HasXY)) static_assert(not is_assignable_to(FooSub, HasXY)) -class FooBool(Foo): +class FooBool: x: bool static_assert(not is_subtype_of(FooBool, HasX))