-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[red-knot] Migrate
is_equivalent_to
unit tests to Markdown tests (#…
- Loading branch information
1 parent
bcf0a71
commit aefb607
Showing
2 changed files
with
35 additions
and
27 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...s/red_knot_python_semantic/resources/mdtest/type_properties/is_equivalent_to.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Equivalence relation | ||
|
||
`is_equivalent_to` implements [the equivalence relation] for fully static types. | ||
|
||
Two types `A` and `B` are equivalent iff `A` is a subtype of `B` and `B` is a subtype of `A`. | ||
|
||
## Basic | ||
|
||
```py | ||
from typing import Any | ||
from typing_extensions import Literal | ||
from knot_extensions import Unknown, is_equivalent_to, static_assert | ||
|
||
static_assert(is_equivalent_to(Literal[1, 2], Literal[1, 2])) | ||
static_assert(is_equivalent_to(type[object], type)) | ||
|
||
static_assert(not is_equivalent_to(Any, Any)) | ||
static_assert(not is_equivalent_to(Unknown, Unknown)) | ||
static_assert(not is_equivalent_to(Any, None)) | ||
static_assert(not is_equivalent_to(Literal[1, 2], Literal[1, 0])) | ||
static_assert(not is_equivalent_to(Literal[1, 2], Literal[1, 2, 3])) | ||
``` | ||
|
||
## Equivalence is commutative | ||
|
||
```py | ||
from typing_extensions import Literal | ||
from knot_extensions import is_equivalent_to, static_assert | ||
|
||
static_assert(is_equivalent_to(type, type[object])) | ||
static_assert(not is_equivalent_to(Literal[1, 0], Literal[1, 2])) | ||
static_assert(not is_equivalent_to(Literal[1, 2, 3], Literal[1, 2])) | ||
``` | ||
|
||
[the equivalence relation]: https://typing.readthedocs.io/en/latest/spec/glossary.html#term-equivalent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters