I believe that all these tests should pass (and I ran it by an LLM, too, which agreed):
from ty_extensions import is_disjoint_from, static_assert
from typing import final, Sequence
from typing_extensions import disjoint_base
class A: ...
class B: ...
@final
class FinalA: ...
@disjoint_base
class DisjointA: ...
class Invariant[T]:
x: T
class InvSubA(Invariant[A]):
pass
class Covariant[T]:
def get(self) -> T:
raise NotImplementedError()
class CoSubB(Covariant[B]):
pass
class CoSubFinalA(Covariant[FinalA]):
pass
class CoSubDisjointA(Covariant[DisjointA]):
pass
static_assert(is_disjoint_from(Invariant[A], Invariant[B]))
static_assert(is_disjoint_from(InvSubA, Invariant[B]))
static_assert(not is_disjoint_from(Invariant[A], Invariant[A]))
static_assert(not is_disjoint_from(Invariant[FinalA], Invariant[FinalA]))
static_assert(not is_disjoint_from(Invariant[DisjointA], Invariant[DisjointA]))
static_assert(not is_disjoint_from(Covariant[A], Covariant[B]))
static_assert(not is_disjoint_from(Covariant[A], CoSubB))
static_assert(is_disjoint_from(Covariant[FinalA], Covariant[B]))
static_assert(is_disjoint_from(CoSubFinalA, Covariant[B]))
static_assert(is_disjoint_from(CoSubDisjointA, Covariant[B]))
static_assert(is_disjoint_from(Covariant[FinalA], CoSubB))
static_assert(is_disjoint_from(Covariant[DisjointA], CoSubB))
static_assert(is_disjoint_from(str, Sequence[int]))
static_assert(not is_disjoint_from(str, Sequence[str]))
Currently we don't detect any of these as disjoint, which means that e.g. we fail to detect some cases of exhaustive matching when we should.
I believe that all these tests should pass (and I ran it by an LLM, too, which agreed):
Currently we don't detect any of these as disjoint, which means that e.g. we fail to detect some cases of exhaustive matching when we should.