@@ -498,3 +498,50 @@ def possibly_unbound_with_invalid_type(flag: bool):
498498 static_assert(is_disjoint_from(G, Callable[... , Any]))
499499 static_assert(is_disjoint_from(Callable[... , Any], G))
500500```
501+
502+ A callable type is disjoint from special form types, except for callable special forms.
503+
504+ ``` py
505+ from ty_extensions import is_disjoint_from, static_assert, TypeOf
506+ from typing_extensions import Any, Callable, TypedDict
507+ from typing import Literal, Union, Optional, Final, Type, ChainMap, Counter, OrderedDict, DefaultDict, Deque
508+
509+ # Most special forms are disjoint from callable types because they are
510+ # type constructors/annotations that are subscripted, not called.
511+ static_assert(is_disjoint_from(Callable[... , Any], TypeOf[Literal]))
512+ static_assert(is_disjoint_from(TypeOf[Literal], Callable[... , Any]))
513+
514+ static_assert(is_disjoint_from(Callable[[], None ], TypeOf[Union]))
515+ static_assert(is_disjoint_from(TypeOf[Union], Callable[[], None ]))
516+
517+ static_assert(is_disjoint_from(Callable[[int ], str ], TypeOf[Optional]))
518+ static_assert(is_disjoint_from(TypeOf[Optional], Callable[[int ], str ]))
519+
520+ static_assert(is_disjoint_from(Callable[... , Any], TypeOf[Type]))
521+ static_assert(is_disjoint_from(TypeOf[Type], Callable[... , Any]))
522+
523+ static_assert(is_disjoint_from(Callable[... , Any], TypeOf[Final]))
524+ static_assert(is_disjoint_from(TypeOf[Final], Callable[... , Any]))
525+
526+ static_assert(is_disjoint_from(Callable[... , Any], TypeOf[Callable]))
527+ static_assert(is_disjoint_from(TypeOf[Callable], Callable[... , Any]))
528+
529+ # However, some special forms are callable (TypedDict and collection constructors)
530+ static_assert(not is_disjoint_from(Callable[... , Any], TypeOf[TypedDict]))
531+ static_assert(not is_disjoint_from(TypeOf[TypedDict], Callable[... , Any]))
532+
533+ static_assert(not is_disjoint_from(Callable[... , Any], TypeOf[ChainMap]))
534+ static_assert(not is_disjoint_from(TypeOf[ChainMap], Callable[... , Any]))
535+
536+ static_assert(not is_disjoint_from(Callable[... , Any], TypeOf[Counter]))
537+ static_assert(not is_disjoint_from(TypeOf[Counter], Callable[... , Any]))
538+
539+ static_assert(not is_disjoint_from(Callable[... , Any], TypeOf[DefaultDict]))
540+ static_assert(not is_disjoint_from(TypeOf[DefaultDict], Callable[... , Any]))
541+
542+ static_assert(not is_disjoint_from(Callable[... , Any], TypeOf[Deque]))
543+ static_assert(not is_disjoint_from(TypeOf[Deque], Callable[... , Any]))
544+
545+ static_assert(not is_disjoint_from(Callable[... , Any], TypeOf[OrderedDict]))
546+ static_assert(not is_disjoint_from(TypeOf[OrderedDict], Callable[... , Any]))
547+ ```
0 commit comments