Skip to content

Commit 07f55a7

Browse files
committed
more tests
1 parent 0fe46b2 commit 07f55a7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

crates/ty_python_semantic/resources/mdtest/protocols.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,20 +2098,23 @@ to be a subtype of a given protocol, even if the other type violates the Liskov
20982098
Principle 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

21042104
class X(Protocol):
21052105
x: int
21062106

21072107
class YProto(X, Protocol):
21082108
x: None = None # TODO: we should emit an error here due to the Liskov violation
21092109

2110+
@final
21102111
class 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

21132114
static_assert(is_subtype_of(YProto, X))
21142115
static_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

21172120
A common use case for this behaviour is that a lot of ecosystem code depends on type checkers
@@ -2126,6 +2129,7 @@ we:
21262129
from typing import Container
21272130

21282131
static_assert(is_subtype_of(str, Container[str]))
2132+
static_assert(not is_disjoint_from(str, Container[str]))
21292133
```
21302134

21312135
This behaviour can have some counter-intuitive repercussions. For example, one implication of this

0 commit comments

Comments
 (0)