I'm looking for a function that can say if a type annotation is a subset of another.
It could be in the standard library or 3rd-party. Since type-checkers such as mypy and pytype have solved this problem, I assume there is some function that can do this, but couldn't find it.
e.g. a function f
such that:
from typing import *
f(Sequence, List) # True
f(Sequence[str], List) # False
f(Iterable[str], List[str]) # True
f(List[str], Iterable[str]) # False
f(str, str) # True
f(int, str) # False
issubclass
works for actual types and simple type annotations,
issubclass(str, str) # True
issubclass(int, str) # False
issubclass(list, Sequence) # True
issubclass(Iterable, Sequence) # False
issubclass(Sequence, Iterable) # True
but not for generics:
issubclass(List[str], Iterable[str])
TypeError: Subscripted generics cannot be used with class and instance checks
The high-level goal is be able to, given two functions, determine if they can be composed.