-
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] Move tuple-containing-Never tests to Markdown (#15402)
## Summary See title. Part of #15397 ## Test Plan Ran new Markdown test. --------- Co-authored-by: Alex Waygood <[email protected]>
- Loading branch information
1 parent
c364b58
commit c874638
Showing
2 changed files
with
33 additions
and
8 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...not_python_semantic/resources/mdtest/type_properties/tuples_containing_never.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,33 @@ | ||
# Tuples containing `Never` | ||
|
||
A heterogeneous `tuple[…]` type that contains `Never` as a type argument simplifies to `Never`. One | ||
way to think about this is the following: in order to construct a tuple, you need to have an object | ||
of every element type. But since there is no object of type `Never`, you cannot construct the tuple. | ||
Such a tuple type is therefore uninhabited and equivalent to `Never`. | ||
|
||
In the language of algebraic data types, a tuple type is a product type and `Never` acts like the | ||
zero element in multiplication, similar to how a Cartesian product with the empty set is the empty | ||
set. | ||
|
||
```py | ||
from knot_extensions import static_assert, is_equivalent_to | ||
from typing_extensions import Never, NoReturn | ||
|
||
static_assert(is_equivalent_to(Never, tuple[Never])) | ||
static_assert(is_equivalent_to(Never, tuple[Never, int])) | ||
static_assert(is_equivalent_to(Never, tuple[int, Never])) | ||
static_assert(is_equivalent_to(Never, tuple[int, Never, str])) | ||
static_assert(is_equivalent_to(Never, tuple[int, tuple[str, Never]])) | ||
static_assert(is_equivalent_to(Never, tuple[tuple[str, Never], int])) | ||
|
||
# The empty tuple is *not* equivalent to Never! | ||
static_assert(not is_equivalent_to(Never, tuple[()])) | ||
|
||
# NoReturn is just a different spelling of Never, so the same is true for NoReturn | ||
static_assert(is_equivalent_to(NoReturn, tuple[NoReturn])) | ||
static_assert(is_equivalent_to(NoReturn, tuple[NoReturn, int])) | ||
static_assert(is_equivalent_to(NoReturn, tuple[int, NoReturn])) | ||
static_assert(is_equivalent_to(NoReturn, tuple[int, NoReturn, str])) | ||
static_assert(is_equivalent_to(NoReturn, tuple[int, tuple[str, NoReturn]])) | ||
static_assert(is_equivalent_to(NoReturn, tuple[tuple[str, NoReturn], int])) | ||
``` |
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