@@ -61,7 +61,7 @@ static_assert(is_disjoint_from(B2, FinalSubclass))
61
61
## Tuple types
62
62
63
63
``` py
64
- from typing_extensions import Literal
64
+ from typing_extensions import Literal, Never
65
65
from knot_extensions import TypeOf, is_disjoint_from, static_assert
66
66
67
67
static_assert(is_disjoint_from(tuple[()], TypeOf[object ]))
@@ -80,6 +80,16 @@ static_assert(is_disjoint_from(tuple[Literal[1], Literal[2]], tuple[Literal[1],
80
80
static_assert(not is_disjoint_from(tuple[Literal[1 ], Literal[2 ]], tuple[Literal[1 ], int ]))
81
81
```
82
82
83
+ If a tuple type contains a ` Never ` element, it is considered similar to ` Never ` itself and is
84
+ disjoint from any other type.
85
+
86
+ ``` py
87
+ static_assert(is_disjoint_from(tuple[Never], tuple[Never]))
88
+ static_assert(is_disjoint_from(tuple[int , Never], tuple[int , Never]))
89
+ static_assert(is_disjoint_from(tuple[int , Never], tuple[Never, int ]))
90
+ static_assert(is_disjoint_from(tuple[int , Never], tuple[int , int ]))
91
+ ```
92
+
83
93
## Unions
84
94
85
95
``` py
@@ -353,3 +363,27 @@ class UsesMeta2(metaclass=Meta2): ...
353
363
354
364
static_assert(is_disjoint_from(type[UsesMeta1], type[UsesMeta2]))
355
365
```
366
+
367
+ ## Callables
368
+
369
+ No two callable types are disjoint because there exists a callable type
370
+ ` (*args: object, **kwargs: object) -> Never ` that is a subtype of all fully static callable types.
371
+
372
+ ``` py
373
+ from knot_extensions import CallableTypeOf, is_disjoint_from, static_assert
374
+ from typing_extensions import Callable, Literal, Never
375
+
376
+ def mixed (a : int , / , b : str , * args : int , c : int = 2 , ** kwargs : int ) -> Never: ...
377
+
378
+ static_assert(not is_disjoint_from(Callable[[], Never], CallableTypeOf[mixed]))
379
+ static_assert(not is_disjoint_from(Callable[[int , str ], float ], CallableTypeOf[mixed]))
380
+
381
+ # Using gradual form
382
+ static_assert(not is_disjoint_from(Callable[... , None ], Callable[[], None ]))
383
+ static_assert(not is_disjoint_from(Callable[... , None ], Callable[... , None ]))
384
+ static_assert(not is_disjoint_from(Callable[... , None ], Callable[[Literal[1 ]], None ]))
385
+
386
+ # Using `Never`
387
+ static_assert(not is_disjoint_from(Callable[[], Never], Callable[[], Never]))
388
+ static_assert(not is_disjoint_from(Callable[[Never], str ], Callable[[Never], int ]))
389
+ ```
0 commit comments