-
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_fully_static
/is_single_valued
/`is_singleton…
…` unit tests to Markdown tests (#15533) ## Summary Part of #15397. ## Test Plan Markdown tests. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
- Loading branch information
1 parent
aed0bf1
commit 6f0b662
Showing
4 changed files
with
135 additions
and
87 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...es/red_knot_python_semantic/resources/mdtest/type_properties/is_fully_static.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,54 @@ | ||
# Fully-static types | ||
|
||
A type is fully static iff it does not contain any gradual forms. | ||
|
||
## Fully-static | ||
|
||
```py | ||
from typing_extensions import Literal, LiteralString, Never | ||
from knot_extensions import Intersection, Not, TypeOf, is_fully_static, static_assert | ||
|
||
static_assert(is_fully_static(Never)) | ||
static_assert(is_fully_static(None)) | ||
|
||
static_assert(is_fully_static(Literal[1])) | ||
static_assert(is_fully_static(Literal[True])) | ||
static_assert(is_fully_static(Literal["abc"])) | ||
static_assert(is_fully_static(Literal[b"abc"])) | ||
|
||
static_assert(is_fully_static(LiteralString)) | ||
|
||
static_assert(is_fully_static(str)) | ||
static_assert(is_fully_static(object)) | ||
static_assert(is_fully_static(type)) | ||
|
||
static_assert(is_fully_static(TypeOf[str])) | ||
static_assert(is_fully_static(TypeOf[Literal])) | ||
|
||
static_assert(is_fully_static(str | None)) | ||
static_assert(is_fully_static(Intersection[str, Not[LiteralString]])) | ||
|
||
static_assert(is_fully_static(tuple[()])) | ||
static_assert(is_fully_static(tuple[int, object])) | ||
|
||
static_assert(is_fully_static(type[str])) | ||
static_assert(is_fully_static(type[object])) | ||
``` | ||
|
||
## Non-fully-static | ||
|
||
```py | ||
from typing_extensions import Any, Literal, LiteralString | ||
from knot_extensions import Intersection, Not, TypeOf, Unknown, is_fully_static, static_assert | ||
|
||
static_assert(not is_fully_static(Any)) | ||
static_assert(not is_fully_static(Unknown)) | ||
|
||
static_assert(not is_fully_static(Any | str)) | ||
static_assert(not is_fully_static(str | Unknown)) | ||
static_assert(not is_fully_static(Intersection[Any, Not[LiteralString]])) | ||
|
||
static_assert(not is_fully_static(tuple[Any, ...])) | ||
static_assert(not is_fully_static(tuple[int, Any])) | ||
static_assert(not is_fully_static(type[Any])) | ||
``` |
25 changes: 25 additions & 0 deletions
25
...s/red_knot_python_semantic/resources/mdtest/type_properties/is_single_valued.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,25 @@ | ||
## Single-valued types | ||
|
||
A type is single-valued iff it is not empty and all inhabitants of it compare equal. | ||
|
||
```py | ||
from typing_extensions import Any, Literal, LiteralString, Never | ||
from knot_extensions import is_single_valued, static_assert | ||
|
||
static_assert(is_single_valued(None)) | ||
static_assert(is_single_valued(Literal[True])) | ||
static_assert(is_single_valued(Literal[1])) | ||
static_assert(is_single_valued(Literal["abc"])) | ||
static_assert(is_single_valued(Literal[b"abc"])) | ||
|
||
static_assert(is_single_valued(tuple[()])) | ||
static_assert(is_single_valued(tuple[Literal[True], Literal[1]])) | ||
|
||
static_assert(not is_single_valued(str)) | ||
static_assert(not is_single_valued(Never)) | ||
static_assert(not is_single_valued(Any)) | ||
|
||
static_assert(not is_single_valued(Literal[1, 2])) | ||
|
||
static_assert(not is_single_valued(tuple[None, int])) | ||
``` |
56 changes: 56 additions & 0 deletions
56
crates/red_knot_python_semantic/resources/mdtest/type_properties/is_singleton.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,56 @@ | ||
# Singleton types | ||
|
||
A type is a singleton type iff it has exactly one inhabitant. | ||
|
||
## Basic | ||
|
||
```py | ||
from typing_extensions import Literal, Never | ||
from knot_extensions import is_singleton, static_assert | ||
|
||
static_assert(is_singleton(None)) | ||
static_assert(is_singleton(Literal[True])) | ||
static_assert(is_singleton(Literal[False])) | ||
|
||
static_assert(is_singleton(type[bool])) | ||
|
||
static_assert(not is_singleton(Never)) | ||
static_assert(not is_singleton(str)) | ||
|
||
static_assert(not is_singleton(Literal[345])) | ||
static_assert(not is_singleton(Literal[1, 2])) | ||
|
||
static_assert(not is_singleton(tuple[()])) | ||
static_assert(not is_singleton(tuple[None])) | ||
static_assert(not is_singleton(tuple[None, Literal[True]])) | ||
``` | ||
|
||
## `NoDefault` | ||
|
||
### 3.12 | ||
|
||
```toml | ||
[environment] | ||
python-version = "3.12" | ||
``` | ||
|
||
```py | ||
from typing_extensions import _NoDefaultType | ||
from knot_extensions import is_singleton, static_assert | ||
|
||
static_assert(is_singleton(_NoDefaultType)) | ||
``` | ||
|
||
### 3.13 | ||
|
||
```toml | ||
[environment] | ||
python-version = "3.13" | ||
``` | ||
|
||
```py | ||
from typing import _NoDefaultType | ||
from knot_extensions import is_singleton, static_assert | ||
|
||
static_assert(is_singleton(_NoDefaultType)) | ||
``` |
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