Skip to content

Commit 35a675f

Browse files
committed
add mixed tuple truthiness tests
1 parent a9ace8f commit 35a675f

File tree

2 files changed

+22
-2
lines changed
  • crates/ty_python_semantic

2 files changed

+22
-2
lines changed

crates/ty_python_semantic/resources/mdtest/type_compendium/tuple.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ class CommonSubtypeOfTuples(I1, I2): ...
296296

297297
## Truthiness
298298

299+
```toml
300+
[environment]
301+
python-version = "3.11"
302+
```
303+
299304
The truthiness of the empty tuple is `False`.
300305

301306
```py
@@ -341,6 +346,21 @@ static_assert(not is_assignable_to(tuple[Literal[False], ...], AlwaysFalsy))
341346
static_assert(not is_assignable_to(tuple[Literal[False], ...], AlwaysTruthy))
342347
static_assert(not is_assignable_to(tuple[Literal[True], ...], AlwaysFalsy))
343348
static_assert(not is_assignable_to(tuple[Literal[True], ...], AlwaysTruthy))
349+
350+
static_assert(is_assignable_to(tuple[int, *tuple[Any, ...]], AlwaysTruthy))
351+
static_assert(is_assignable_to(tuple[int, *tuple[bool, ...]], AlwaysTruthy))
352+
static_assert(is_assignable_to(tuple[int, *tuple[Literal[False], ...]], AlwaysTruthy))
353+
static_assert(is_assignable_to(tuple[int, *tuple[Literal[True], ...]], AlwaysTruthy))
354+
355+
static_assert(is_assignable_to(tuple[*tuple[Any, ...], int], AlwaysTruthy))
356+
static_assert(is_assignable_to(tuple[*tuple[bool, ...], int], AlwaysTruthy))
357+
static_assert(is_assignable_to(tuple[*tuple[Literal[False], ...], int], AlwaysTruthy))
358+
static_assert(is_assignable_to(tuple[*tuple[Literal[True], ...], int], AlwaysTruthy))
359+
360+
static_assert(is_assignable_to(tuple[int, *tuple[Any, ...], int], AlwaysTruthy))
361+
static_assert(is_assignable_to(tuple[int, *tuple[bool, ...], int], AlwaysTruthy))
362+
static_assert(is_assignable_to(tuple[int, *tuple[Literal[False], ...], int], AlwaysTruthy))
363+
static_assert(is_assignable_to(tuple[int, *tuple[Literal[True], ...], int], AlwaysTruthy))
344364
```
345365

346366
Both of these results are conflicting with the fact that tuples can be subclassed, and that we

crates/ty_python_semantic/src/types/tuple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,10 +886,10 @@ impl<'db> TupleSpec<'db> {
886886
// Two tuples with an incompatible number of required elements must always be disjoint.
887887
let (self_min, self_max) = self.size_hint();
888888
let (other_min, other_max) = other.size_hint();
889-
if self_max.is_some_and(|max|max < other_min) {
889+
if self_max.is_some_and(|max| max < other_min) {
890890
return true;
891891
}
892-
if other_max.is_some_and(|max|max < self_min) {
892+
if other_max.is_some_and(|max| max < self_min) {
893893
return true;
894894
}
895895

0 commit comments

Comments
 (0)