@@ -329,7 +329,7 @@ Its subtyping follows the general rule for subtyping of gradual types.
329329from typing import Any
330330from ty_extensions import static_assert, is_subtype_of
331331
332- static_assert(is_subtype_of(tuple[Any, ... ], tuple[Any, ... ]))
332+ static_assert(not is_subtype_of(tuple[Any, ... ], tuple[Any, ... ]))
333333static_assert(not is_subtype_of(tuple[Any, ... ], tuple[Any]))
334334static_assert(not is_subtype_of(tuple[Any, ... ], tuple[Any, Any]))
335335static_assert(not is_subtype_of(tuple[Any, ... ], tuple[int , ... ]))
@@ -340,7 +340,7 @@ static_assert(not is_subtype_of(tuple[Any, ...], tuple[int, int]))
340340Same applies when ` tuple[Any, ...] ` is unpacked into a mixed tuple.
341341
342342``` py
343- static_assert(is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[int , * tuple[Any, ... ]]))
343+ static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[int , * tuple[Any, ... ]]))
344344static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[Any, ... ]))
345345static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[Any]))
346346static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[Any, Any]))
@@ -349,7 +349,7 @@ static_assert(not is_subtype_of(tuple[int, *tuple[Any, ...]], tuple[int, ...]))
349349static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[int ]))
350350static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ]], tuple[int , int ]))
351351
352- static_assert(is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[* tuple[Any, ... ], int ]))
352+ static_assert(not is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[* tuple[Any, ... ], int ]))
353353static_assert(not is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[Any, ... ]))
354354static_assert(not is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[Any]))
355355static_assert(not is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[Any, Any]))
@@ -358,7 +358,7 @@ static_assert(not is_subtype_of(tuple[*tuple[Any, ...], int], tuple[int, ...]))
358358static_assert(not is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[int ]))
359359static_assert(not is_subtype_of(tuple[* tuple[Any, ... ], int ], tuple[int , int ]))
360360
361- static_assert(is_subtype_of(tuple[int , * tuple[Any, ... ], int ], tuple[int , * tuple[Any, ... ], int ]))
361+ static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ], int ], tuple[int , * tuple[Any, ... ], int ]))
362362static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ], int ], tuple[Any, ... ]))
363363static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ], int ], tuple[Any]))
364364static_assert(not is_subtype_of(tuple[int , * tuple[Any, ... ], int ], tuple[Any, Any]))
@@ -594,13 +594,13 @@ static_assert(is_subtype_of(TypeIs[str], int))
594594from ty_extensions import is_equivalent_to, is_subtype_of, static_assert
595595from typing_extensions import TypeGuard, TypeIs
596596
597- static_assert(is_subtype_of(TypeGuard[int ], TypeGuard[int ]))
598- static_assert(is_subtype_of(TypeGuard[bool ], TypeGuard[int ]))
597+ # TODO : TypeGuard
598+ # static_assert(is_subtype_of(TypeGuard[int], TypeGuard[int]))
599+ # static_assert(is_subtype_of(TypeGuard[bool], TypeGuard[int]))
599600static_assert(is_subtype_of(TypeIs[int ], TypeIs[int ]))
600601static_assert(is_subtype_of(TypeIs[int ], TypeIs[int ]))
601602
602- # TODO : TypeGuard
603- static_assert(not is_subtype_of(TypeGuard[int ], TypeGuard[bool ])) # error: [static-assert-error]
603+ static_assert(not is_subtype_of(TypeGuard[int ], TypeGuard[bool ]))
604604static_assert(not is_subtype_of(TypeIs[bool ], TypeIs[int ]))
605605static_assert(not is_subtype_of(TypeIs[int ], TypeIs[bool ]))
606606```
@@ -763,49 +763,44 @@ static_assert(is_subtype_of(LiteralBase | LiteralUnrelated, object))
763763
764764## Non-fully-static types
765765
766- A non-fully-static type ` A ` can be considered a subtype of another type ` B ` if all possible
767- materializations of ` A ` are a subtype of some possible materialization of ` B ` , and all possible
768- materializations of ` B ` are a supertype of some possible materialization of ` A ` .
766+ A non-fully-static type can be considered a subtype of another type if all possible materializations
767+ of the first type represent sets of values that are a subset of every possible set of values
768+ represented by a materialization of the second type .
769769
770770``` py
771771from ty_extensions import Unknown, is_subtype_of, static_assert, Intersection
772772from typing_extensions import Any
773773
774- static_assert(is_subtype_of(Any, Any))
774+ static_assert(not is_subtype_of(Any, Any))
775775static_assert(not is_subtype_of(Any, int ))
776776static_assert(not is_subtype_of(int , Any))
777777static_assert(is_subtype_of(Any, object ))
778778static_assert(not is_subtype_of(object , Any))
779779
780780static_assert(is_subtype_of(int , Any | int ))
781- static_assert(is_subtype_of(Any, Any | int ))
782781static_assert(is_subtype_of(Intersection[Any, int ], int ))
783782static_assert(not is_subtype_of(tuple[int , int ], tuple[int , Any]))
784783```
785784
786785The same for ` Unknown ` :
787786
788787``` py
789- static_assert(is_subtype_of(Unknown, Unknown))
790- static_assert(is_subtype_of(Any, Unknown))
791- static_assert(is_subtype_of(Unknown, Any))
788+ static_assert(not is_subtype_of(Unknown, Unknown))
792789static_assert(not is_subtype_of(Unknown, int ))
793790static_assert(not is_subtype_of(int , Unknown))
794791static_assert(is_subtype_of(Unknown, object ))
795792static_assert(not is_subtype_of(object , Unknown))
796793
797794static_assert(is_subtype_of(int , Unknown | int ))
798- static_assert(is_subtype_of(Unknown, Unknown | int ))
799795static_assert(is_subtype_of(Intersection[Unknown, int ], int ))
800796static_assert(not is_subtype_of(tuple[int , int ], tuple[int , Unknown]))
801797```
802798
803799Instances of classes that inherit ` Any ` are not subtypes of some other arbitrary class, because the
804800` Any ` they inherit from could materialize to something that is not a subclass of that class.
805801
806- They are also not subtypes of ` Any ` , because some materializations of ` Any ` (for example, a
807- materialization into some unrelated final type) are not a super-type of any materialization of a
808- specific class inheriting ` Any ` .
802+ Similarly, they are not subtypes of ` Any ` , because there are possible materializations that would
803+ not satisfy the subtype relation.
809804
810805They are subtypes of ` object ` .
811806
@@ -824,7 +819,7 @@ static_assert(is_subtype_of(InheritsAny, object))
824819Similar for subclass-of types:
825820
826821``` py
827- static_assert(is_subtype_of(type[Any], type[Any]))
822+ static_assert(not is_subtype_of(type[Any], type[Any]))
828823static_assert(not is_subtype_of(type[object ], type[Any]))
829824static_assert(not is_subtype_of(type[Any], type[Arbitrary]))
830825static_assert(is_subtype_of(type[Any], type[object ]))
0 commit comments