Variance inference and subtyping #16

Merged
HEL merged 3 commits from feat/variance into main 2026-06-20 14:55:02 +00:00
Owner

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 VarianceInferrer class 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 AppliedType instances of the same generic base, taking into account the variance of type variables.

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 `VarianceInferrer` class 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 `AppliedType` instances of the same generic base, taking into account the variance of type variables.
HEL self-assigned this 2026-06-20 14:54:56 +00:00
HEL added 3 commits 2026-06-20 14:54:56 +00:00
HEL merged commit 12782dda1e into main 2026-06-20 14:55:02 +00:00
HEL deleted branch feat/variance 2026-06-20 14:55:02 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: HEL/midas#16