[red-knot] Migrate is_equivalent_to unit tests to Markdown tests (#15470)
## Summary Part of #15397, built on top of #15469. ## Test Plan Markdown tests.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user