Variance inference and subtyping #16
Reference in New Issue
Block a user
Delete Branch "feat/variance"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR implements variance for type variables. To make UX pleasant for Python users who may not be familiar with type theory and variance, this property is inferred from usages of said variables.
It adds a
VarianceInferrerclass which walks a generic type definition recursively and tracks the polarity of its parameters' use sites, determining the final variance of each type variable.The subtyping relationship check is also extended to handle comparing two
AppliedTypeinstances of the same generic base, taking into account the variance of type variables.