@@ -2098,20 +2098,23 @@ to be a subtype of a given protocol, even if the other type violates the Liskov
20982098Principle in some way.
20992099
21002100``` py
2101- from typing import Protocol
2102- from ty_extensions import static_assert, is_subtype_of
2101+ from typing import Protocol, final
2102+ from ty_extensions import static_assert, is_subtype_of, is_disjoint_from
21032103
21042104class X (Protocol ):
21052105 x: int
21062106
21072107class YProto (X , Protocol ):
21082108 x: None = None # TODO : we should emit an error here due to the Liskov violation
21092109
2110+ @final
21102111class YNominal (X ):
2111- x = None # TODO : we should emit an error here due to the Liskov violation
2112+ x: None = None # TODO : we should emit an error here due to the Liskov violation
21122113
21132114static_assert(is_subtype_of(YProto, X))
21142115static_assert(is_subtype_of(YNominal, X))
2116+ static_assert(not is_disjoint_from(YProto, X))
2117+ static_assert(not is_disjoint_from(YNominal, X))
21152118```
21162119
21172120A common use case for this behaviour is that a lot of ecosystem code depends on type checkers
@@ -2126,6 +2129,7 @@ we:
21262129from typing import Container
21272130
21282131static_assert(is_subtype_of(str , Container[str ]))
2132+ static_assert(not is_disjoint_from(str , Container[str ]))
21292133```
21302134
21312135This behaviour can have some counter-intuitive repercussions. For example, one implication of this
0 commit comments